移动滚动触发 jQuery 调整大小事件 -(仅在使用移动设备时触发,在浏览器视口中正常)
Mobile scroll fires jQuery resize event - (it only fires when using mobile, ok in browser viewport)
This is my code here it works fine on browser but not on mobile, am
not that expert in jQuery so if there is any mistake, do forgive me.ty
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;
}
});
我在 Whosebug 本身 link of the solution 中找到了答案。 sidonaldson
的回答帮助我解决了 issue.ty
这是代码
var cachedWidth = $(window).width();
$(window).resize(function(){
var newWidth = $(window).width();
if(newWidth !== cachedWidth){
//DO RESIZE HERE
cachedWidth = newWidth;
}
});
This is my code here it works fine on browser but not on mobile, am not that expert in jQuery so if there is any mistake, do forgive me.ty
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;
}
});
我在 Whosebug 本身 link of the solution 中找到了答案。 sidonaldson
的回答帮助我解决了 issue.ty
这是代码
var cachedWidth = $(window).width();
$(window).resize(function(){
var newWidth = $(window).width();
if(newWidth !== cachedWidth){
//DO RESIZE HERE
cachedWidth = newWidth;
}
});