如何在调整窗口大小小于767px后刷新页面一次?
我尝试了很多例子,但效果不好。
$(document).ready(function(){
if ($(window).width() < 767) {
location.reload(); // refresh page
}
else {
// width more than 768px for PC
}
});
请帮助〜
答案 0 :(得分:3)
$(document).ready(function(){
$(window).on('resize',function(){
if ($(window).width() < 767) {
location.reload(); // refresh page
}
else {
// width more than 768px for PC
}
});
});
答案 1 :(得分:0)
如果不想早点重新加载,你可能会这样延迟:
$(document).ready(function() {
$(window).on("resize", function() {
var tm;
clearTimeout(tm);
tm = setTimeout(function() {
if ($(window).width() < 767) {
location.reload(); // refresh page
}
else {
// width more than 768px for PC
}
}, 100);
});
});