2017-01-11 8 views
0

ウィンドウのサイズが変わったときに一度だけリロードします。jQueryを使用してページとブレークポイントブランチを再ロードするにはどうすればよいですか?

ウィンドウサイズを変更した場合は、リロードを1回だけ実行します。

なぜなら、PCはタブを使い、スマートフォンはアコーディオンに変わるからです。

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

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

location.reload(); 

} else { 

} 

答えて

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/

関連する問題