weB*_*Ber 1 mobile jquery resize
这是我的代码,它在浏览器上很好用,但在移动设备上却不能用,不是jQuery的专家,所以如果有任何错误,请原谅我。
var width = $(window).width(), height = $(window).height();
$(window).on('resize', function() {
if($(window).width() != width && $(window).height() != height)
{
var width = $(window).width(), height = $(window).height();
//do something here;
}
});
Run Code Online (Sandbox Code Playgroud)
我在StackOverflow本身的解决方案链接中找到了答案。这sidonaldson就是帮助我解决问题的答案。
这是代码
var cachedWidth = $(window).width();
$(window).resize(function(){
var newWidth = $(window).width();
if(newWidth !== cachedWidth){
//DO RESIZE HERE
cachedWidth = newWidth;
}
});
Run Code Online (Sandbox Code Playgroud)