我想知道在窗口调整大小时,如果用户扩展或缩小视口,我怎么能检测到?
一个一般的想法是这个,但我不知道如何实现它:
$(window).resize(function() {
var initialWidth = ...;
var initialHeight = ...;
var finalWidth = ...;
var finalHeight = ...;
if ((initialWidth < finalWidth) || (initialHeight < finalHeight)) {
return 'expand';
} else {
return 'shrink';
}
});
谢谢
答案 0 :(得分:2)
你可以尝试一下:
var initialWidth;
var initialHeight;
$(document).ready(function(){
initialWidth = $(window).width();
initialHeight = $(window).height();
})
$(window).resize(function() {
var finalWidth = $(window).width();
var finalHeight = $(window).height();
var result;
if ((initialWidth < finalWidth) || (initialHeight < finalHeight)) {
result = 'expand';
} else {
result = 'shrink';
}
initialWidth = finalWidth;
initialHeight = finalHeight;
return result;
});