javascript - JQuery, wrong left position -


i have code:

$(this).closest("p").after('<strong>' + armess[icurindex] + '</strong>').next().animate({             top: $(this).offset().top - 57,             left: -$(this).width() //[first value] here 148px on chrome , 150px on firefox          }, 300,function(){             alert($(this).offset().top - 57);             alert(-$(this).width()); //[second value] here true width 1 want present left         }); 

code overview: at first line animate strong element

as can see 2 different values -$(this).width():

the first value: during animation process.

the second value: after animation finished.

if got idea reason 2 different values, thankful.

the problem here javascript keyword this not have same value in inner function called after animation when setting width. first value this object triggers animation. in function alert called this object being animated.

try this:

var $strongelement = $(this).closest("p").after('<strong>' + armess[icurindex] + '</strong>').next();  $strongelement.animate({        top: $(this).offset().top - 57,        left: -$strongelement.width()      }, 300, function(){     alert(-$(this).width());  }); 

see http://jsfiddle.net/vtyjf/


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -