简体   繁体   English

jquery 如何写 if (window.width() < 1200 && after window.resize() window.width() > 1200){}

[英]jquery how to write if (window.width() < 1200 && after window.resize() window.width() > 1200){}

hello i was wondering how to write this function so i could reload my page when a user resizes in those specific conditions...my ui breaks on resizes >1200px< because it uses an ajax request to load the correct navigation on page load.您好,我想知道如何编写此函数,以便在用户在这些特定条件下调整大小时重新加载我的页面……我的 ui 在调整大小 >1200px< 时中断,因为它使用 ajax 请求在页面加载时加载正确的导航。 I want to be able to fire a reload function after the user resizes and goes from 900px to 1300px but not fire if the user were to go from 900px to 950px我希望能够在用户调整大小并从 900px 变为 1300px 后触发重新加载功能,但如果用户从 900px 变为 950px 则不会触发

thank you so much for taking the time to answer ^.^非常感谢您抽出时间来回答^.^

anyways i was able to read up on variables and how to use them with the window.width() and heres the solution:无论如何,我能够阅读变量以及如何将它们与 window.width() 一起使用,这是解决方案:

$(window).ready(function() {
var $fwidth = $(window).width();

$(window).on('resize', function() {
var $nwidth = $(window).width();

if($fwidth > 1200 && $nwidth < 1200){
  location.reload();
}

if($fwidth < 1200 && $nwidth > 1200){
  location.reload();
}
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM