The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

function doesn't return value

Hi,

I've written this code that examines the viewport width onload and when the viewport is re-sized...if it's more than 800px an element in my layout is given a margin. It's for an element that we can't use css to position in an extremely complex layout.

It works fine (the dollar shortcuts are just saying getElementByID) but it doesn't return the value when the browser is re-sized...i can alert the value out, so it's working fine but it doesnt get assigned to the element at the end..i think i have something simple wrong...does returning the value in the function mean that it's available to the last line when the value is assigned as a margin to my element? Or is my problem that the marginLeft variable in the function is only local to my function? If so how do i fix?

Your onresize event handler that you define in the middle of that function won't run "inside" that function. It might as well be defined outside the function. You can't return the value to the next line of your function, it doesnt work like that.
I'd try something like:

Now it works but the div only moves to its new position (due to the new margin) when i let go of the mouse button after ive re-sized the viewport...so it kind of jumps....is there any way to do this so the box moves real time?

I'm looking at faebook and they have a new chat feature which shows up as a grey bar alwasy at the bottom of the viewport...this moves real time with the resize...this must be javascript right?

In IE onresize fires continuously throughout a resize event, I think that FF and maybe Opera only fire it at the end of the event (when the mouse button is released). Perhaps they capture the mousedown/mousemove events to handle resizing smoothly.