update div position on window resize
I'm trying to change the position of a div as the window is resized using jQuery.
Here's my code:
So when I resize the window, #slider doesn't move. If I put a fixed number into the code on the last line, it works fine.
newWinWidth = $(window).width();
var pos = $('#slider').position();
var page = Math.floor(Math.abs(pos.left)/winWidth);
var offset = winWidth - newWinWidth;
var leftPos = pos.left + (offset * page) + 'px';
Can anyone shed any light on the best way to approach this problem?
Many thanks in advance,