[英]Separate functions based on screen width (changes on resize)
I have a website navigation giving me problems. 我的网站导航给我带来了问题。 What I am after is having a mobile navigation and a more robust fullscreen navigation. 我需要的是移动导航和更强大的全屏导航。 I have dumbed this down so you can see my problem. 我把这个问题哑了下来,这样您就可以看到我的问题。 I would like this to dynamically change the if/else based on the current window size... right now if you start on if it stays on if no matter what the window size, and vis versa. 我希望这可以根据当前窗口大小动态更改if / else ...现在,如果无论窗口大小如何,如果它保持打开状态,现在就开始,反之亦然。
Thanks for any help! 谢谢你的帮助!
var w = $(window).width();
function checkSize() {
if ( w < 770 ) {
console.log("This is a small window");
} else {
console.log("This is a big window");
};
};
$(window).resize(checkSize);
checkSize();
You have to move var w = $(window).width();
您必须移动var w = $(window).width();
to the checkSize
function. 到checkSize
函数。
我猜您可能应该看看“ 媒体查询 ”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.