Question

I am having trouble animating jquery knob. As you can see in my example only the last one animates.

<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

Was it helpful?

Solution

local $this object was not getting set for every new instance of knob,instead same this object was referenced each time.

so what you need to do is create a new local reference of this object for every knob instance.

var $this = $(this);

Live Demo @ JSFiddle

JS CODE:

     $('.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');
          }
       });
   });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top