如何使用jQuery重新加载页面和断点分支?

时间:2017-01-11 01:19:37

标签: javascript jquery

我只想在窗口大小改变时重新加载一次。

更改窗口大小时,只需执行一次重新加载。

原因是个人电脑使用标签和智能手机变成手风琴。

if (window.matchMedia('screen and (max-width:767px)').matches) {

location.reload();
} else if (window.matchMedia('screen and (min-width:768px)').matches) {

location.reload();

} else {

}

1 个答案:

答案 0 :(得分:0)

您可以使用setTimeout()

var resizeListener;

//the amount of time to wait after the resizing has finished before calling our function
var pause = 500;

$(window).resize(function(){

  //every time the window resize is called cancel the setTimeout() function
  clearTimeout(resizeListener);

  //set out function to run after a specified amount of time 
  resizeListener = setTimeout(function(){
    alert("The user has done resizing the window");
  },pause);

});

来源:https://thepixel.ninja/jquery/how-to-run-a-function-after-window-resize-using-jquery/