簡體   English   中英

我如何在每次在jquery中調用此函數時添加自定義動畫持續時間

[英]how do i add a custom animate duration for every time i call this function in jquery

$(document).ready(function(){   

  var el = $("#box");

  animate(el,300,function(){

  });


});


function animate(el,leftVal,callback){

el.animate({
    left : leftVal
},{
    duration : 2000,
    queue    : false,
    easing   : "swing",
    complete : function(){
        //alert("finished");
        if(callback){
            callback();
        }
    }
});

}

在函數中添加一個duration參數:

function animate(el, leftVal, callback, duration) {

然后在函數的持續時間部分中調用參數:

{
    duration: duration,
    ...
}

調用函數時,定義最后一個參數(現在是持續時間):

$(document).ready(function() {
    var el = $("#box");
    animate(el, 300, function() {
    },1000); // 1 second duration (1000 milliseconds)
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM