【问题标题】:Jquery knob animateJquery 旋钮动画
【发布时间】:2013-05-07 10:07:09
【问题描述】:

我在为 jquery 旋钮设置动画时遇到问题。 正如您在我的示例中看到的,只有最后一个动画。

<input class="knob nummer1 animated" value="0" rel="64">
       <input class="knob nummer2 animated" value="0" rel="77">
       <input class="knob nummer3 animated" value="0" rel="99">

link

【问题讨论】:

    标签: jquery-knob


    【解决方案1】:

    本地$this 对象没有为旋钮的每个新实例设置,而是每次都引用相同的this 对象。

    所以您需要为每个旋钮实例创建一个 this 对象的新本地引用。

    var $this = $(this);

    Live Demo @ JSFiddle

    JS 代码:

         $('.knob').each(function() {
           var $this = $(this);
           var myVal = $this.attr("rel");
           $this.knob({
           });
           $({
              value: 0
           }).animate({
              value: myVal
           }, {
              duration: 2000,
              easing: 'swing',
              step: function() {
                 $this.val(Math.ceil(this.value)).trigger('change');
              }
           });
       });
    

    【讨论】:

    • 谢谢。很接近,但我想要动画中的整数
    • @Johansrk:我没听明白?动画中的整数是什么意思?
    • 动画期间,数字不完整。看起来像“ceil”,不起作用
    • @Johansrk: 比你这更让我烦恼的兄弟,你知道错误是什么,`$this = $(this);` $this 这里没有得到更新了,所以当我像这样更改它时 `var $this = $(this);` 它起作用了。你能相信这是错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多