成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Web設計師值得收藏的10個jQuery特效

開發 前端
jQuery已經不是什么新鮮的事兒,以前總把它認為是非常難的東西,也就沒有認真去了解他了。這篇文章的最重要內容是來自Web Designer Wall的一篇教程,一篇包含了10個jQuery特效的教程。

jQuery已經不是什么新鮮的事兒,以前總把它認為是非常難的東西,也就沒有認真去了解他了。直到學完CSS的大部分內容,才開始接觸這種"write less, do more" 的Javascrīpt框架。這篇文章的最重要內容是來自Web Designer Wall的一篇教程,一篇包含了10個jQuery特效的教程。這里不打算全文翻譯,想以自己的語言來表達,或許這樣更方便大家理解/自己以后學習,也可能更準確地描述。

先試試看?特效實例:

View jQuery Demos:http://www.webdesignerwall.com/demo/jquery/

jQuery是如何工作的?

首先,你需要下載一個jQuery版本,并將它插入到<head>標簽內。然后,你將需要寫函數來告訴jQuery做些什么,下面的這個圖表將告訴你jQuery是怎樣工作的(請點擊圖片,查看大圖):

jQuery是怎樣工作的

如何獲取元素(Get the element)?

書寫jQuery函數是一個非常簡單的事。關鍵是你要學習如何獲取你想要實現的效果的確切元素。

  1. ("#header") = 獲取 id="header" 的元素   
  2. ("h3") = 獲取所有<h3>   
  3. ("div#content .photo") = 獲取<div id="content">里  
  4.   所有用class="photo"定義的元素   
  5. ("ul li") = 獲取所以 <ul> 中 <li> 的元素   
  6. ("ul li:first") = 只獲取<ul>中第一個<li>  

1. 簡單的下拉面板

讓我們來開始這個簡單的下拉面板特效吧,或許你已經見過很多次,現在,自己試試吧:

簡單的下拉面板

當包含class="btn-slide"的元素被點擊,它會下拉/上提<div id="panel">里的元素。然后切換到CSS中的class="active"到<a class="btn-slide">元素。.active 將會以CSS的方式打開/關閉出面板。

  1. $(document).ready(function(){  
  2.  
  3.  $(".btn-slide").click(function(){     
  4.  $("#panel").slideToggle("slow");     
  5.  $(this).toggleClass("active");   
  6.  });  
  7.  
  8. }); 

view demo:http://www.webdesignerwall.com/demo/jquery/simple-slide-panel.html

2. 簡單的隱藏效果

如圖,當右上角的上圖標被點擊時,內容被隱藏。

簡單的隱藏效果

當被定義為 <img class="delete"> 的圖片被點擊,它會手找到父級元素 <div class="pane"> 并激活它的能力,慢慢消失,隱藏起來。

  1. $(document).ready(function(){  
  2.  
  3.  $(".pane .delete").click(function(){     
  4.  $(this).parents(".pane").animate({ opacity: "hide" }, "slow");   
  5.  });  
  6.  
  7. }); 

view demo:http://www.webdesignerwall.com/demo/jquery/simple-disappear.html

3 連續過渡效果

讓我們來看看jQuery連貫性的威力吧。只需要幾行代碼,我能讓這個方塊漸變+縮放比例地飛來飛去。

連續過渡效果

Line 1: 當 <a class="run"> 被點擊

Line 2: 激活 <div id="box"> 的不透明度(opacity)=0.1,直到值達到400px,速度達到1200px/ms

Line 3: 當opacity=0.4, top=160px,height=20,width=20,以"slow"顯示

Line 4: 當opacity=1, left=0, height=100, width=100,也以"slow"顯示

Line 5: 當opacity=1, left=0, height=100, width=100, 也以"slow"顯示

Line 6: 當top=0, 以"fast"顯示

Line 7: 然后,以常速上滑 (default speed = "normal")

Line 8: 然后以"slow"下滑

Line 9:返回失效會阻止瀏覽器跳向鏈接錨點

  1. $(document).ready(function(){  
  2.  
  3.  $(".run").click(function(){  
  4.  
  5.    $("#box").animate({opacity: "0.1", left: "+=400"}, 1200)     
  6.    .animate({opacity: "0.4", top: "+=160", height: "20", width: "20"}, "slow")     
  7.    .animate({opacity: "1", left: "0", height: "100", width: "100"}, "slow")     
  8.    .animate({top: "0"}, "fast")     
  9.    .slideUp()     
  10.    .slideDown("slow")     
  11.    return false;  
  12.  
  13.  });  
  14.  
  15. }); 

view demo:http://www.webdesignerwall.com/demo/jquery/chainable-effects.html

4a. 可折疊的模式 #1

這是第一個可折疊的樣式。

可折疊的模式

第一行將向<div class="accordion"> 內的第一個<H3> 添加一個CSS class為"active"的值。 第二行剛是隱藏<div class="accordion">內非第一個< p >的內容。當 <h3> 被點擊時,當前<p>下拉,而原先下拉的<p> 上提。

  1. $(document).ready(function(){  
  2.  
  3.  $(".accordion h3:first").addClass("active");   
  4.  $(".accordion p:not(:first)").hide();  
  5.  $(".accordion h3").click(function(){  
  6.  $(this).next("p").slideToggle("slow")     
  7.  .siblings("p:visible").slideUp("slow");     
  8.  $(this).toggleClass("active");     
  9.  $(this).siblings("h3").removeClass("active");  
  10.  
  11.  });  
  12.  
  13. }); 

view demo:http://www.webdesignerwall.com/demo/jquery/accordion1.html

4b. 可折疊模式 #2

這個實例與#1非常類似,不過,它會讓指定的面板像默認面板一樣打開。

在CSS樣式表中,設置.accordion p 為 display:none。現在,如果你像默認打開的樣式一樣,打開第三個面板,你可以寫$(".accordion2 p").eq(2).show(); (eq = equal)來實現它,需要注意的是起始點是"0",而不是"1",所以,第三個相應的是"2",而不是"3"。

  1. $(document).ready(function(){  
  2.  
  3.  $(".accordion2 h3").eq(2).addClass("active");   
  4.  $(".accordion2 p").eq(2).show();  
  5.  $(".accordion2 h3").click(function(){     
  6.  $(this).next("p").slideToggle("slow")     
  7.  .siblings("p:visible").slideUp("slow");     
  8.  $(this).toggleClass("active");     
  9.  $(this).siblings("h3").removeClass("active"); });  
  10.  
  11. }); 

view demo:http://www.webdesignerwall.com/demo/jquery/accordion2.html

5a. 鼠標經過激活效果 #1

這個將會實現一個非常漂亮的,當鼠標經過時出現漸變出現的效果。當鼠標經過菜單時,它會尋找緊接著的<em>,并在上方激活它的不透明度。

鼠標經過激活效果

  1. $(document).ready(function(){  
  2.  
  3.  $(".menu a").hover(function() {     
  4.  $(this).next("em").animate({opacity: "show", top: "-75"}, "slow");   
  5.  }, function()   
  6.  {     
  7.  $(this).next("em").animate({opacity: "hide", top: "-85"}, "fast");   
  8.  });  
  9.  
  10. }); 

view demo:http://www.webdesignerwall.com/demo/jquery/animated-hover1.html

5b. 鼠標經過激活 #2

這個實例會顯示菜單中鏈接的title 屬性attribute,讓其以變數方式存在,并添加<em>標簽。第一行會添加一個空的<em>到菜單的<a>元素。當鼠標經過菜單鏈接時,它會顯示title的屬性,讓它以"hoverText(隱藏)"的形式顯示,并使<em>中的文字顯示隱藏文本的值。

鼠標經過激活

 

  1. $(document).ready(function(){  
  2.  
  3.  $(".menu2 a").append("<em></em>");  
  4.  
  5.  $(".menu2 a").hover(function() {     
  6.  $(this).find("em").animate({opacity: "show", top: "-75"}, "slow");     
  7.  var hoverText = $(this).attr("title");     
  8.  $(this).find("em").text(hoverText);   
  9.  }, function() {     
  10.  $(this).find("em").animate({opacity: "hide", top: "-85"}, "fast");   
  11.  });  
  12.  
  13. }); 

view demo:http://www.webdesignerwall.com/demo/jquery/animated-hover2.html

#p#

6. 整塊可點擊性效果

這個實例將會教你如何實現內容中元素可點擊性效果,Best Web Gallery的側邊欄Tab就顯示這樣的效果。

整塊可點擊性效果

如果你想讓class="pane-list"的<ul>內的 <li> 可點擊(整塊),你可以向 ".pane-list li"指派一個函數,使它被點擊時,函數找到 <a>元素,重定向到它的href屬性值。

  1. $(document).ready(function(){  
  2.  
  3.  $(".pane-list li").click(function(){     
  4.  window.location=$(this).find("a").attr("href"); return false;   
  5.  });  
  6.  
  7. }); 

view demo:http://www.webdesignerwall.com/demo/jquery/block-clickable.html

7. 可收縮面板

讓我們組合一下上面的實例,創造一給可收縮的面板(像Gmai收件箱面板l)。作者還在Web Designer Wall 的評論列表Next2Friends里應用這個。

可收縮面板

First line: 隱藏<div class="message_body">里第一個元素以后的元素

Second line: 隱藏所有第5個<li>后面的元素

Third part: 當<p class="message_head">被點擊里,顯示/隱藏<div class="message_body">

Fourth part: 當<a class="collpase_all_message"> 被點擊時,上提所有<div class="message_body">的元素

Fifth part: 當<a class="show_all_message"> 被點擊,隱藏它,并顯示<a class="show_recent_only">,并下拉第5個<li>以后的元素

Sixth part: 當<a class="show_recent_only"> 被點擊時,隱藏它,并顯示<a class="show_all_message">,并上提第5個 <li>以后的元素

  1. $(document).ready(function(){  
  2.  
  3.  //hide message_body after the first one   
  4.  $(".message_list .message_body:gt(0)").hide();  
  5.  
  6.  //hide message li after the 5th   
  7.  $(".message_list li:gt(4)").hide();  
  8.  
  9.  //toggle message_body   
  10.  $(".message_head").click(function(){     
  11.  $(this).next(".message_body").slideToggle(500)     
  12.  return false; });  
  13.  
  14.  //collapse all messages $(".collpase_all_message").click(function(){     
  15.  $(".message_body").slideUp(500)   return false; });  
  16.  
  17.  //show all messages   
  18.  $(".show_all_message").click(function(){     
  19.  $(this).hide()     
  20.  $(".show_recent_only").show()     
  21.  $(".message_list li:gt(4)").slideDown()     
  22.  return false; });  
  23.  
  24.  //show recent messages only   
  25.  $(".show_recent_only").click(function(){     
  26.  $(this).hide()     
  27.  $(".show_all_message").show()     
  28.  $(".message_list li:gt(4)").slideUp()     
  29.  return false; });  
  30.  
  31. }); 

view demo:http://www.webdesignerwall.com/demo/jquery/collapsible-panels.html

8. 模仿WordPress后臺評論管理面板

我想你可能見過最多次這個效果是在Wordpress后臺的評論管理面板。那好,讓我們來用jQuery來模仿它的效果。為了實現背景顏色,你需要包含Color Animations這個插件。

模仿WordPress后臺評論管理面板

First line: 向<div class="pane"> 添加 "alt" class

Second part: 當<a class="btn-delete">被點擊,激活<div class="pane">的不透明度

Third part: 當<a class="btn-unapprove">被點擊, 首先讓<div class="pane">顯示黃色,然后變為白色,并添加類(addClass)"spam"

Fourth part: 當<a class="btn-approve">被點擊,首先讓<div class="pane">顯示綠色,然后變為白色,并移除類(removeClass)"spam"

Fifth part: 當<a class="btn-spam">被點擊,激活背景色為red并使其opacity ="hide"

  1. //don't forget to include the Color Animations plugin//<script type="text/javascript" src="jquery.color.js"></script> 
  2. $(document).ready(function(){  
  3.  
  4.  $(".pane:even").addClass("alt");  
  5.  
  6.  $(".pane .btn-delete").click(function(){     
  7.  alert("This comment will be deleted!");  
  8.  
  9.    $(this).parents(".pane").animate({ backgroundColor: "#fbc7c7" }, "fast")     
  10.    .animate({ opacity: "hide" }, "slow")     
  11.    return false; });  
  12.  
  13.  $(".pane .btn-unapprove").click(function(){     
  14.  $(this).parents(".pane").animate({ backgroundColor: "#fff568" }, "fast")     
  15.  .animate({ backgroundColor: "#ffffff" }, "slow")     
  16.  .addClass("spam")     
  17.  return false; });  
  18.  
  19.  $(".pane .btn-approve").click(function(){     
  20.  $(this).parents(".pane").animate({ backgroundColor: "#dafda5" }, "fast")     
  21.  .animate({ backgroundColor: "#ffffff" }, "slow")     
  22.  .removeClass("spam")     
  23.  return false; });  
  24.  
  25.  $(".pane .btn-spam").click(function(){     
  26.  $(this).parents(".pane").animate({ backgroundColor: "#fbc7c7" }, "fast")     
  27.  .animate({ opacity: "hide" }, "slow")     
  28.  return false; });  
  29.  
  30. });  

view demo:http://www.webdesignerwall.com/demo/jquery/wordpress-comments.html

9. 輪換圖片展欄

如果你有一個項目需要顯示多個圖片,并且你不希望鏈向另一個頁面,那么你可以在當前面加載目標鏈接的JPG。

輪換圖片展欄

首先,添加一個<em>到H2標簽。

當<p class=thumbs>內的元素被點擊:

◆以可視的形式顯示href屬性的"largePath"路徑

◆以可視的形式顯示title 屬性的"largeAlt"

◆代換<img id="largeImg">的scr屬性內可視的"largePath"路徑,并代換alt屬性內可視的"largeAlt"

◆設置em內的內容(h2內) 為可視的largeAlt

  1. $(document).ready(function(){  
  2.  
  3.  $("h2").append('<em></em>')  
  4.         $(".thumbs a").click(function(){  
  5.         var largePath = $(this).attr("href");     
  6.  var largeAlt = $(this).attr("title");  
  7.         $("#largeImg").attr({ src: largePath, alt: largeAlt });  
  8.         $("h2 em").html(" (" + largeAlt + ")"); return false; });  
  9.  
  10. }); 

view demo:http://www.webdesignerwall.com/demo/jquery/img-replacement.html

10. 個性化不同的鏈接樣式

在現代化的瀏覽器中,個性化不同的鏈接是非常容易的事,比如想讓.pdf文件顯示特殊的樣式,你只需要添加上簡單的CSS規則:a[href $='.pdf'] { ... }就可以實現,但不幸的是IE6并不支持這個。如果想實現這個,你可以利用jQuery。

個性化不同的鏈接樣式

前三行代碼必需是連續的,它只是一個<a>的href屬性中的一個CSS class。第二部分將會獲取所有href中沒有"http://www.webdesignerwall.com" 和/或沒有"#"的< a>元素,并添加"external" class和target= "_blank"。

  1. $(document).ready(function(){  
  2.  
  3.  $("a[@href$=pdf]").addClass("pdf");  
  4.  
  5.  $("a[@href$=zip]").addClass("zip");  
  6.  
  7.  $("a[@href$=psd]").addClass("psd");  
  8.  
  9.  $("a:not([@href*=http://www.webdesignerwall.com])").not("[href^=#]")     
  10.  .addClass("external")     
  11.  .attr({ target: "_blank" });  
  12.  
  13. }); 

view demo:http://www.webdesignerwall.com/demo/jquery/link-types.html

【編輯推薦】

  1. jQuery 1.4實用技巧大放送
  2. Django創始人:從技術工藝上考量jQuery
  3. 20個最新jQuery插件震撼登場(多圖) 
責任編輯:王曉東 來源: sofish.de
相關推薦

2011-03-28 08:51:41

網頁設計WebSEO

2012-09-24 01:49:48

jQueryjQuery插件Web

2011-04-21 15:33:23

2013-01-18 17:00:20

設計師創業團隊

2012-03-28 09:49:55

WEB特效

2013-04-11 09:48:52

Web設計師云計算

2013-04-24 13:47:38

云計算

2013-07-22 10:01:03

JavascriptWeb

2019-04-22 15:00:05

CSS前端開發

2012-06-04 15:24:56

jQuery

2017-03-23 10:21:57

CSS3動效庫前端

2011-05-16 09:30:38

jQuery

2021-11-10 11:13:02

C#設計模式

2018-04-26 10:48:36

機器學習神經網絡TensorFlow

2010-11-11 09:15:08

Web應用程序

2011-08-03 11:08:27

HTML 5

2012-04-16 10:08:05

2011-07-05 15:53:35

CSS

2015-12-08 09:10:12

菜鳥總監優秀設計師
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 97久久久| 亚洲精品不卡 | 玖玖免费 | 欧美男人天堂 | 一级黄色毛片子 | 免费黄色日本 | 黄免费观看视频 | 综合久久av | 国产亚洲精品精品国产亚洲综合 | 福利社午夜影院 | 亚洲精品片 | 中文字幕在线视频精品 | 免费a网 | 欧美一区二区三区 | 国产精品久久国产精品久久 | 狠狠做六月爱婷婷综合aⅴ 国产精品视频网 | 国产福利在线 | 精品一级毛片 | 高清av在线 | 成年人的视频免费观看 | 中文字幕一区二区三区在线观看 | 欧美区在线 | 亚洲一区自拍 | 国产精品 欧美精品 | 欧美一级免费片 | 久久精品免费 | 日韩精品免费在线观看 | 亚洲 欧美 日韩 精品 | 综合色在线 | 国产日韩精品一区二区 | 国产色婷婷精品综合在线手机播放 | 欧美日韩综合一区 | 国产精品精品视频一区二区三区 | 成人小视频在线免费观看 | 亚洲欧美日韩在线一区二区 | 久久精品一 | 中文字幕欧美一区 | 久久九九99 | 欧美日韩国产高清 | 日韩精品一区二区三区第95 | 国产高清在线精品 |