NeverEndingFlashStories
asked on
jquery on window resize and initial window value
Hi,
I am doing some jquery css modification for a responsive site , where the menu and other divs relocate themselves as the window is resized, or if the initial size of the window is that of a mobile equivalent.
I would like to do the equivalent of :
if (initial window size<1024 || window.resize) {
Do something;
}
However, the jquery function of $(window).resize(function( ){ Do something }) does not seem to allow an if operator.
So far the only solution i can think of is to repeat the method twice, which seems silly. (see below)
if ($(window).width()<1024) {
Do something;
}
$(window).resize(function( ){ Do something;});
Is there a more elegant solution to this?
Thanks.
I am doing some jquery css modification for a responsive site , where the menu and other divs relocate themselves as the window is resized, or if the initial size of the window is that of a mobile equivalent.
I would like to do the equivalent of :
if (initial window size<1024 || window.resize) {
Do something;
}
However, the jquery function of $(window).resize(function(
So far the only solution i can think of is to repeat the method twice, which seems silly. (see below)
if ($(window).width()<1024) {
Do something;
}
$(window).resize(function(
Is there a more elegant solution to this?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Nevermind....nothing is working right now under document.ready, so..... something else outside the scope of my question is probably wrong.
Thanks for the help!
Thanks for the help!
Take out that document ready function wrapper.
Make sure you have a jQuery library v1.7 or newer.
Make sure you have a jQuery library v1.7 or newer.
ASKER
I figured it out...i was modifying the code of index.php, while refreshing about.php and wondering why nothing happens.
...its lunch time.
Thanks for the quick responses :).
...its lunch time.
Thanks for the quick responses :).
Just noticed an error in my suggested delay code. In the "else" section, newW is out of scope so I would use $(this).width() instead.
Thanks for the points.
Thanks for the points.
ASKER
Gotcha. cheers :)
ASKER
Thanks - this looks like it should work, and the tips on time checking is great.
Is there a requirement for me to run this? For some reason it isnt working for me :
Open in new window