hi,
how can i write this if/ else condition in jquery??
if window resize, run this code,
$(window).resize(function(){
var height_window = $(window).height();
var width_window = $(window).width();
var margin_left = (width_window/2) - (840/2);
$('.slide').css({width:width_window+'px'});
$('.content').css({marginLeft:margin_left+'px'});
$('#enter').click(function () {
$('#container').animate({marginLeft:'-'+width_window+'px'}, 600);
return false;
});
$('#back').click(function () {
$('#container').animate({marginLeft:'0px'}, 600);
return false;
});
});
else run this,
var height_window = $(window).height();
var width_window = $(window).width();
var margin_left = (width_window/2) - (840/2);
$('.slide').css({width:width_window+'px'});
$('.content').css({marginLeft:margin_left+'px'});
$('#enter').click(function () {
$('#container').animate({marginLeft:'-'+width_window+'px'}, 600);
return false;
});
thanks,
Lau
If we completely remove the onresize event and code that would run from the example, how/when/why would the other code run?
this is the implementation of the window resize and getting the width of the window,
http://partexchangeco.org.uk/home.php
i would like to get the window width when the window is being resized so i am told to use window.resize().
so i want to put it in this logic,
if window size, run this code,
{…}
else, run as usual,
{…}
is it possible?
Your question doesn’t make any sense, I guess because you don’t understand what resize() does.
$(window).resize() doesn’t return true/false, it returns jQuery object $(window), so you can’t use your logic. That code assigns a function to onresize event of window object, it doesn’t run that function, it doesn’t resize window, it doesn’t check if window was resized, it ONLY assigns it. That function will be ran whenever window is resized.
CyberAlien:
Your question doesn’t make any sense, I guess because you don’t understand what resize() does.
$(window).resize() doesn’t return true/false, it returns jQuery object $(window), so you can’t use your logic. That code assigns a function to onresize event of window object, it doesn’t run that function, it doesn’t resize window, it doesn’t check if window was resized, it ONLY assigns it. That function will be ran whenever window is resized.
thank you. now i understand…
how can i check if window is being resized or not (of cos not using window.resize!)?
thanks,
Lau
99.99999999999% of the time, the window is not being resized. When the onresize event fires, the window is being resized. You might want to read up a bit on even based programing in javascript.
event based programing.
stupid disappearing edit button
thank you. i will have a read on that thanks