-1

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

slide.stop();

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

slide.css('left');

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?

1 Answers1

1

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

Amin Jafari
  • 7,157
  • 2
  • 18
  • 43