jQuery this selector not available to animate() method properies -


can explain me why "this" selector not available animate() methods properties.

see 1st example @ http://jsfiddle.net/qzvv4/, there no errors produced ignores it.

 $('#test1 .bar[data-percentage]').animate({      width: $(this).attr('data-percentage'),      easing: 'easeoutbounce'  }, 1000, function () {      $(this).text($(this).attr('data-percentage'));  }); 

because this isn't referring element. you're still in same scope, this doesn't change. you'd have instead:

// need easing plugin // https://github.com/danro/jquery-easing  $('#test1 .bar[data-percentage]').each(function() {     var $this = $(this);      $this.animate({         width: $this.data('percentage')     }, {         duration: 1000,         //easing: 'easeoutbounce',         step: function(value) {             $(this).text(value + '%');         }     }); }); 

demo: http://jsfiddle.net/qzvv4/4/


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -