javascript - How to change the left attribute on page resize (jQuery) -



javascript - How to change the left attribute on page resize (jQuery) -

i'm having slight troubles code. i'm trying create these element's css property 'left' update according difference of it's current left value, , amount page resizes. way, when page resizes , background moves over, elements move too. take @ code below , i'll describe issue:

$(window).resize(function() { var docwidth = $(window).width(); if (docwidth < 1000) { var difference = 1000-docwidth; $('#headnav a,#icons div').each(function() { var left = $(this).position().left; var newleft = left - difference; $(this).css({ 'left' : newleft }); }); } });

so issue i'm getting elements beingness given left values of wild numbers, while value of variable 'newleft' reasonable, desired value. each function think collecting sums of these values , running them each element x amount of times elements found exist (so if there's 5 elements runs 5 times, mean.) want code execute uniquely each element, 1 time each, not each element 10 times! (that's how many elements in html).

so question is, how can achieved? hope explained myself enough, tough iterate. help extremely appreciated. give thanks you!

here's fun trick: include += in .css() call:

$(this).css({left: "+=" + difference});

jquery math new value.

javascript jquery resize element each

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -