JQuery animate動(dòng)畫應(yīng)用示例
本文實(shí)例講述了JQuery animate動(dòng)畫。分享給大家供大家參考,具體如下:
滑動(dòng)選項(xiàng)卡
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style type="text/css"> .btns input{ width: 100px; height: 40px; background-color: grey; border: 0; } .btns .current{ background-color: gold; } .cons .slides div{ width: 500px; height: 300px; background-color: gold; /*display: none;!*整體都不顯示了*!*/ text-align: center; line-height: 300px; font-size: 30px; float: left;/*把三個(gè)div由隱藏改為浮動(dòng)*/ } .cons{ width: 500px; height: 300px; overflow: hidden; /*超過(guò)cons的slide隱藏*/ position: relative;/*相對(duì)于slide絕對(duì)定位*/ } .slides{ width: 1500px; height: 300px; /*把slide加長(zhǎng)*/ position: absolute;/*相對(duì)于cons相對(duì)定位*/ } .cons .active{ display: block; } </style> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script type="text/javascript"> $(function () { var $btn=$('.btns input'); var $slides=$('.cons .slides'); // alert($btn.length); // alert($div.length); $btn.click(function () { // 我點(diǎn)擊哪一個(gè)按鈕,$(this)就指的是誰(shuí),而this //指的是原生的,$(this)指的是JQuery的 // $(this).siblings().removeClass('current'); // $(this).addClass('current');//可以用鏈?zhǔn)秸{(diào)用 $(this).addClass('current').siblings().removeClass('current'); // var num=$(this).index(); // $div.eq($(this).index()).addClass('active').sibling().removeClass('active'); $slides.animate({left:(-500*$(this).index())}); }) }) </script> </head> <body> <div class="btns"> <input type="button" name="" value="01" class="current"> <input type="button" name="" value="02"> <input type="button" name="" value="03"> </div> <div class="cons"> <div class="slides"> <div >選項(xiàng)卡1的內(nèi)容</div> <div>選項(xiàng)卡2的內(nèi)容</div> <div>選項(xiàng)卡3的內(nèi)容</div> </div> </div> </body> </html>
將slides下面的div由隱藏改為浮動(dòng),將cons設(shè)置成絕對(duì)定位,將slides改為相對(duì)定位。超過(guò)cons的slides隱藏。
點(diǎn)擊事件發(fā)生之后,相對(duì)定位改變。
animate動(dòng)畫
$div=$('#div1'); $div.animate({ width:300, height:300 },1000,'swing',function () { alert('done'); })
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script type="text/javascript"> $(function () { $box=$('.box'); $box.animate({ width:300, height:300 },1000,'swing',function () { alert('done'); }) }) </script> <style type="text/css"> .box{ width: 100px; height: 100px; background-color: gold; } </style> </head> <body> <div class="box"></div> </body> </html>
用animate動(dòng)畫改變box大小,完成之后用回調(diào)函數(shù)彈出done
感興趣的朋友可以使用如下工具測(cè)試上述代碼運(yùn)行效果:
在線HTML/CSS/JavaScript代碼運(yùn)行工具:
http://tools.jb51.net/code/HtmlJsRun
在線HTML/CSS/JavaScript前端代碼調(diào)試運(yùn)行工具:
http://tools.jb51.net/code/WebCodeRun
更多關(guān)于jQuery相關(guān)內(nèi)容還可查看本站專題:《jQuery動(dòng)畫與特效用法總結(jié)》、《jQuery切換特效與技巧總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jQuery常見(jiàn)經(jīng)典特效匯總》及《jquery選擇器用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
相關(guān)文章
基于MVC3方式實(shí)現(xiàn)下拉列表聯(lián)動(dòng)(JQuery)
點(diǎn)擊一個(gè)下拉框,則另一個(gè)下拉框的值發(fā)生對(duì)應(yīng)變化。如:選擇中國(guó),則另個(gè)一下拉框里顯示中國(guó)各個(gè)省份,具體實(shí)現(xiàn)如下,感興趣的朋友可以參考下2013-09-09jQuery代碼實(shí)現(xiàn)對(duì)話框右上角菜單帶關(guān)閉×
這篇文章主要介紹了jQuery代碼實(shí)現(xiàn)對(duì)話框右上角菜單帶關(guān)閉× 的相關(guān)資料,需要的朋友可以參考下2016-05-05jquery實(shí)現(xiàn)的元素的left增加N像素 鼠標(biāo)移開(kāi)會(huì)慢慢的移動(dòng)到原來(lái)的位置
鼠標(biāo)移動(dòng)上去,元素的left增加N像素,鼠標(biāo)移開(kāi)會(huì)慢慢的移動(dòng)到原來(lái)的位置2010-03-03jQuery checkbox選中問(wèn)題之prop與attr注意點(diǎn)分析
這篇文章主要介紹了jQuery checkbox選中問(wèn)題之prop與attr注意點(diǎn),結(jié)合form表單實(shí)例形式分析了針對(duì)火狐瀏覽器下checkbox失效情況的處理技巧,需要的朋友可以參考下2016-11-11jQuery實(shí)現(xiàn)可編輯表格并生成json結(jié)果(實(shí)例代碼)
這篇文章主要介紹了 jquery實(shí)現(xiàn)可編輯表格并生成json結(jié)果,該代碼解析和加載功能都用前端js實(shí)現(xiàn),簡(jiǎn)化了后臺(tái)代碼邏輯,非常不錯(cuò),具有參考借鑒加載,需要的朋友可以參考下2017-07-07一步步教大家編寫酷炫的導(dǎo)航欄js+css實(shí)現(xiàn)
一步步教大家編寫酷炫的導(dǎo)航欄,js+css實(shí)現(xiàn)黑色經(jīng)典導(dǎo)航欄,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-03-03