日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

jQuery动画2

發(fā)布時間:2024/2/28 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 jQuery动画2 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

先展示一下結(jié)構(gòu)與樣式部分

三個按鈕控制小方塊的運動

代碼如下

<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>.demo {width: 50px;height: 50px;background-color: darkcyan;position: absolute;left: 70px;top: 70px;}button {width: 50px;height: 30px;line-height: 30px;outline: none;border: none;border-radius: 3px;background-color: #ccc;color: #fff;cursor: pointer;margin-bottom: 5px;display: inline-block;}</style> </head><body><button class="run">run</button><button class="stop">stop</button><button class="finish">finish</button><div class="demo"></div> </body>

?.animate()

作用:根據(jù)一組 CSS 屬性,執(zhí)行自定義動畫??蓚鲄?shù):target,duration,easing,callback

【例1】實現(xiàn)兩段運動,效果如下

方法一:回調(diào)函數(shù)實現(xiàn)

<!-- jQuery庫 --> <script src="./jquery.js"></script> <!-- easing --> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.4.1/jquery.easing.min.js'></script> <script>//傳參 target duration easing callback$('button').click(function name(params) {$('.demo').animate({width:'+=30px', height: '+=30px', left: '+=150px', top: '+=150px'}, 1000, 'linear',function () {$('.demo').animate({width:'+=30px', height: '+=30px', left: '+=150px', top: '-=150px'}, 1000, 'linear');});}) </script>

方法二:鏈?zhǔn)秸{(diào)用

$('.run').click(function name(params) {$('.demo').animate({ width: '+=30px', height: '+=30px', left: '+=150px', top: '+=150px' }, 1000, 'linear').delay(1000).animate({ width: '+=30px', height: '+=30px', left: '+=150px', top: '-=150px' }, 1000, 'linear');})

.stop()

作用:停止匹配元素當(dāng)前正在運行的動畫,可傳參數(shù) null, true, (true, true)

【例1】在上例中添加stop方法,使動畫停止

情況1:傳null

//stop(null)—— 結(jié)束當(dāng)前動畫,直接執(zhí)行下一動畫 $('.stop').click(function () {$('.demo').stop(); })

效果:由下圖可知點擊stop按鈕之后,結(jié)束當(dāng)前動畫,執(zhí)行delay,再執(zhí)行下一動畫

情況2:傳true

//stop(true) —— 直接停止所有動畫 $('.stop').click(function () {$('.demo').stop(true); })

效果

情況3:傳(true, true)

//stop(true,true) —— 停止當(dāng)前動畫,跳到當(dāng)前動畫的目標(biāo)位置,并且結(jié)束所有動畫 $('.stop').click(function () {$('.demo').stop(true,true); })

效果


.finish()

作用:停止當(dāng)前正在運行的動畫,刪除所有排隊的動畫,并完成匹配元素所有的動畫

代碼

$('.finish').click(function () {console.log(1);$('.demo').finish(); })

效果如下

?

總結(jié)

以上是生活随笔為你收集整理的jQuery动画2的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。