Retrieving new value of margin-left that has already been changed with jQuery
I'm developing a horizontal slideshow in jQuery and have run into a problem. The slideshow works, fundamentally, by filling an overflow-hidden div (#ss_inner) with images, and decreasing the left margin into negative territoy to advance the show. My slideshow processing loop calls a function with the following logic:
- var current_margin = $("#ss_inner").css('margin-left').replace('px','');
- var new_margin = ((current_margin - 316) + 'px');
- var current_width = $("#ss_inner").width();
- var new_width = ((current_width + 316) + 'px');
- $("#ss_inner").css({
- 'width':new_width
- })
- .animate({
- 'margin-left':new_margin
- }, 2000)
- ;
- });
My problem is that the value returned for current_margin on line 1 is the same each time the loop runs - 960px, the value that is specified in the CSS.
- Is there another way to retrieve margin-left so as to return the current, calculated value rather than the value specified in the CSS?
- If not, should I simply set new_margin as a persistent variable and substitute it for the retrieved value in subsequent runs of the loop?
Thanks!