添加缓动到一个简单的小 jquery 插件?不工作

发布于 2024-12-29 06:55:07 字数 830 浏览 1 评论 0原文

有人可以告诉我如何向这个插件添加缓动。我知道有一个缓动插件,yada yada,我只是希望这个插件在使用它时可以选择添加缓动和回调。我尝试在 speed, 之后添加单词 easing,所以它看起来像 speed, easing,callback,但由于某种原因它不起作用?

jQuery.fn.animateAuto = function(prop, speed, callback){
    var elem, height, width;
    return this.each(function(i, el){
        el = jQuery(el), elem = el.clone().css({"height":"auto","width":"auto"}).appendTo("body");
        height = elem.css("height"),
        width = elem.css("width"),
        elem.remove();

        if(prop === "height")
            el.animate({"height":height}, speed, callback);
        else if(prop === "width")
            el.animate({"width":width}, speed, callback);  
        else if(prop === "both")
            el.animate({"width":width,"height":height}, speed, callback);
    });  
}

Can someone tell me how to add easing to this plugin. I understand there's an easing plugin, yada yada, I just want this plugin to have the option of adding easing AND a callback when using it. I tried adding the word easing after speed,, so it looked like speed, easing, callback, but for some reason it didn't work?

jQuery.fn.animateAuto = function(prop, speed, callback){
    var elem, height, width;
    return this.each(function(i, el){
        el = jQuery(el), elem = el.clone().css({"height":"auto","width":"auto"}).appendTo("body");
        height = elem.css("height"),
        width = elem.css("width"),
        elem.remove();

        if(prop === "height")
            el.animate({"height":height}, speed, callback);
        else if(prop === "width")
            el.animate({"width":width}, speed, callback);  
        else if(prop === "both")
            el.animate({"width":width,"height":height}, speed, callback);
    });  
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情何以堪。 2025-01-05 06:55:07

应该是这样的:


el.animate(
  {height:your_height_value}, 
  speed, 
  'swing', //example easing here
  complete: function() {  //your callback, just an example
    //do something
  }
);

你的意思是这样吗

It should be like:


el.animate(
  {height:your_height_value}, 
  speed, 
  'swing', //example easing here
  complete: function() {  //your callback, just an example
    //do something
  }
);

Did you mean something like this

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文