jQuery 常用特效實(shí)例小結(jié)【顯示與隱藏、淡入淡出、滑動、動畫等】
本文實(shí)例講述了jQuery 常用特效。分享給大家供大家參考,具體如下:
顯示與隱藏
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> #content{display: none;} </style> <script src="jQuery/jquery-1.8.3.js"></script> <script type="text/javascript"> $('#btn').click(function(event) { if ($(this).text() === '顯示說明') { $('#content').show(); //$('#content').show('slow');//設(shè)置顯示速度,1000為一秒,也可以用fast或slow //$('#content').show('slow',function() { //$('h3').css('color','red'); //});//設(shè)置顯示完成后的回調(diào)函數(shù) $(this).text('隱藏說明'); } else { $('#content').hide(); $(this).text('顯示說明'); } }); }); </script> </head> <body> <img src="images/logo.jpg" alt='logo' style="width: 300px"> <div> <p id="content">百度logo,埃里克森上放聲大哭就會發(fā)生放聲大哭肌膚時(shí)受到了飛機(jī)上的法律手段無可奈何花落去</p> </div> <div style="clear: both"> <button type="button" name="button" id="btn">顯示說明</button> </div> </body> </html>
淡入與淡出
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> #content{display: none;} </style> <script src="jQuery/jquery-1.8.3.js"></script> <script type="text/javascript"> //1、淡入 $('#fadeIn').click(function(event) { $('#group1 img:first').fadeIn('slow'); $('#group1 img:eq(1)').fadeIn('fast'); $('#group1 img:last').fadeIn(3000,function() { alert('淡入'); }); }); //2、淡出 $('#fadeOut').click(function(event) { $('#group2 img:first').fadeOut('slow'); $('#group2 img:eq(1)').fadeOut('fast'); $('#group2 img:last').fadeOut(3000,function() { alert('淡出'); }); }); //3、淡入/淡出結(jié)合 $('#fadeToggle').click(function(event) { $('#group3 img:first').fadeToggle('slow'); $('#group3 img:eq(1)').fadeToggle('fast'); $('#group3 img:last').fadeToggle(3000,function() { alert('淡入/淡出結(jié)合'); }); }); //4、設(shè)置褪色級別 $('#fadeTo').click(function(event) { $('#group4 img:first').fadeTo('slow',0.6); $('#group4 img:eq(1)').fadeTo('fast',0.4); $('#group4 img:last').fadeTo(3000,0.2,function() { alert('圖片褪色'); }); }); }); </script> <style> #group1 img{display: none;} </style> </head> <body> <div id="group1"> <button type="button" name="button" id="fadeIn">淡入</button> <img src="images/1.png" alt=""> <img src="images/2.png" alt="" width="100px"> <img src="images/3.png" alt=""> </div> <div id="group2"> <button type="button" name="button" id="fadeOut">淡出</button> <img src="images/1.png" alt=""> <img src="images/2.png" alt="" width="100px"> <img src="images/3.png" alt=""> </div> <div id="group3"> <button type="button" name="button" id="fadeToggle">淡入/淡出自動</button> <img src="images/1.png" alt=""> <img src="images/2.png" alt="" width="100px"> <img src="images/3.png" alt=""> </div> <div id="group4"> <button type="button" name="button" id="fadeTo">設(shè)置褪色級別</button> <img src="images/1.png" alt=""> <img src="images/2.png" alt="" width="100px"> <img src="images/3.png" alt=""> </div> </body> </html>
滑動
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>滑動效果</title> <style> #wrap img{width: 100px;} /*#content {width: 100px;display: none;}*//*向下滑動*/ </style> <script type="text/javascript"></script> <script src="jQuery/jquery-1.8.3.min.js"></script> <script> $(document).ready(function() { //1、向下滑動 $('#wrap img').bind('click',function() { // $('#content').slideDown('slow'); $('#content').slideDown('slow',function(event) { $('#wrap img').fadeOut('slow',function(event) { $(this).attr('src','images/3.png').fadeIn('slow'); }); }); }); //2、向上滑動 $('#wrap img').bind('click',function() { // $('#content').slideUp('slow'); $('#content').slideUp('slow',function(event) { $('#wrap img').fadeOut('slow',function(event) { $(this).attr('src','images/3.png').fadeIn('slow'); }); }); }); //3、展開與收起切換 $('#wrap img').bind('click',function() { // $('#content').slideToggle('slow'); $('#content').slideToggle('slow',function(event) { $('#wrap img').fadeOut('slow',function(event) { if ($(this).attr('src') == 'images/3.png') { $(this).attr('src','images/2.png').fadeIn('slow'); } else { $(this).attr('src','images/3.png').fadeIn('slow'); } }); }); }); }); </script> </head> <body> <div id='wrap'> <div id='content'> <h3>百度</h3> <p>要福克斯地方思考就回復(fù)剞城飄飄㱒發(fā)生糾紛還是葉</p> </div> <img src="images/2.png" alt="百度"> </div> </body> </html>
動畫實(shí)例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>動畫</title> <style> img{width: 0;opacity: 0;} .content{display: none;} </style> <script src="jQuery/jquery-1.8.3.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#btn').click(function(event) { $('img').before('<br>'); //當(dāng)按鈕內(nèi)容為顯示時(shí),修改按鈕內(nèi)容,顯示圖片和說明 if ($(this).text() == '顯示') { $(this).text('隱藏'); $('img').animate({//動畫屬性對象(必選) width:200,//屬性必須是css屬性,只支持?jǐn)?shù)字型,不支持字體顏色 opacity:1,//屬性值單位:默認(rèn)為px },{//動畫選項(xiàng)屬性(可選) duration:3000, complete:function(event) { $('.content').slideDown(3000); } }); } else {//當(dāng)按鈕內(nèi)容為隱藏時(shí),修改按鈕內(nèi)容,隱藏圖片和說明 $(this).text('顯示'); $('img').animate({//動畫屬性對象(必選) width:0, opacity:0, },{//動畫選項(xiàng)屬性(可選) duration:3000, complete:function(event) { $('.content').slideUp(3000); } }); } }); }); </script> </head> <body> <button type="button" name="button" id="btn">顯示</button> <img src="images/2.png" alt="baidu"> <div class="content"> <p>富士康地方就是看適當(dāng)放寬了;收款方式斯洛伐克但是</p> </div> </body> </html>
感興趣的朋友可以使用在線HTML/CSS/JavaScript代碼運(yùn)行工具:http://tools.jb51.net/code/HtmlJsRun測試上述代碼運(yùn)行效果。
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery頁面元素操作技巧匯總》、《jQuery常見事件用法與技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對大家jQuery程序設(shè)計(jì)有所幫助。
- jQuery動畫與特效詳解
- JQuery 動畫卷頁 返回頂部 動畫特效(兼容Chrome)
- jQuery動畫效果圖片輪播特效
- 基于jquery和svg實(shí)現(xiàn)超炫酷的動畫特效
- jQuery實(shí)現(xiàn)鼠標(biāo)經(jīng)過顯示動畫邊框特效
- 基于jquery css3實(shí)現(xiàn)點(diǎn)擊動畫彈出表單源碼特效
- jQuery圖片切換動畫特效
- jQuery+jRange實(shí)現(xiàn)滑動選取數(shù)值范圍特效
- JQuery實(shí)現(xiàn)簡單的圖片滑動切換特效
- jquery實(shí)現(xiàn)滑動特效代碼
- 基于jQuery制作小圖標(biāo)上下滑動特效
相關(guān)文章
jquery 插件實(shí)現(xiàn)圖片延遲加載效果代碼
前幾天上QQ的在線視頻網(wǎng)站,看到上面的影片列表頁的圖片有這樣一種效果:當(dāng)向下拉動滾動條時(shí)下面的圖片才開始加載,就是說它不會一下子把所有的圖片都加載出來,拉動滾動條后用戶看到了才會顯示,這是一個(gè)很不錯(cuò)的用戶體驗(yàn)。2010-02-02jQuery實(shí)現(xiàn)鎖定頁面元素(表格列)
這篇文章主要為大家詳細(xì)介紹了jQuery實(shí)現(xiàn)鎖定頁面元素,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02分享2個(gè)jQuery插件--jquery.fileupload與artdialog
這篇文章主要介紹了分享2個(gè)jQuery插件--jquery.fileupload與artdialog的使用方法及示例,非常的實(shí)用,這里推薦給大家。2014-12-12javascript基于jQuery的表格懸停變色/恢復(fù),表格點(diǎn)擊變色/恢復(fù),點(diǎn)擊行選Checkbox
jQuery的表格懸停變色 恢復(fù),表格點(diǎn)擊變色/恢復(fù),點(diǎn)擊行選Checkbox2008-08-08jQuery easyui datagird編輯行刪除行功能的實(shí)現(xiàn)代碼
這篇文章主要介紹了jQuery easyui datagird編輯行刪除行功能的實(shí)現(xiàn)代碼,需要的朋友可以參考下2018-09-09jQuery 判斷是否包含在數(shù)組中Array[]的方法
下面小編就為大家?guī)硪黄猨Query 判斷是否包含在數(shù)組中Array[]的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-08-08