本文實例講述了jQuery實現(xiàn)基本淡入淡出效果的方法。分享給大家供大家參考,具體如下:
jQuery fadeIn()方法:用于淡入已隱藏的元素
jQuery fadeOut()方法:用于淡出可見的元素
<!DOCTYPE html><html><head><script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script><script>$(document).ready(function(){$("button").click(function(){$("#div1").fadeIn();});});</script></head><body><p>演示帶有不同參數(shù)的fadeIn()方法。</p><button>點擊</button><br /><div id="div1" style="width:80px;height:80px;display:none;background-color:red;"></div></body></html>運行結果:

jQuery fadeToggle()方法:方法可以在fadeIn()與fadeOut()方法之間進行切換
語法:$(selector).fadeToggle(speed,callback);
如果元素已淡出,則fadeToggle()會向元素添加淡入效果
如果元素已淡入,則fadeToggle()會向元素添加淡出效果
<!DOCTYPE html><html><head><script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script><script>$(document).ready(function(){$("button").click(function(){$("#div1").fadeToggle();});});</script></head><body><button>點擊</button><br/><div id="div1" style="width:80px;height:80px;background-color:red;"</div></body></html>運行結果:

jQuery fadeTo()方法:允許漸變?yōu)榻o定的不透明(值介于0與1之間)
語法:$(selector).fadeTo(speed,opacity,callback);
<!DOCTYPE html><html><head><script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script><script>$(document).ready(function(){$("button").click(function(){$("#div1").fadeTo(1000,0.2);});});</script></head><body><button>點擊</button><br/><div id="div1" style="width:80px;height:80px;background-color:red;"</div></body></html>運行結果:

感興趣的朋友可以使用在線HTML/CSS/JavaScript代碼運行工具http://tools.VeVB.COm/code/HtmlJsRun測試上述代碼運行效果。
更多關于jQuery相關內容還可查看本站專題:《jQuery切換特效與技巧總結》、《jQuery擴展技巧總結》、《jQuery常用插件及用法總結》、《jQuery拖拽特效與技巧總結》、《jQuery表格(table)操作技巧匯總》、《jQuery常見經(jīng)典特效匯總》、《jQuery動畫與特效用法總結》及《jquery選擇器用法總結》
希望本文所述對大家jQuery程序設計有所幫助。
新聞熱點
疑難解答