Erik Moldtmann Erik Moldtmann - 8 months ago 34
Javascript Question

JS get element position after animation interrupt

I have an element, which I move across the screen using an animation:

slide.animate({'left': value*100 + '%'}, transitiontime * 1000)

When a specific event occurs, I stop the animation using


now I want to get the current 'left' value using


but unfortunately I get a 'px' value instead of percent, which I used in the animation.
Is there a way to get the percent value?


this happens because css() actually uses javascript's getcomputedstyle() function and it always returns in pixels.

you can achieve what you want like this:

var left=(100 / $(window).width()) * parseInt(slide.css('left').split('px')[0]) + '%';

the above code returns a value in percentage DEMO