How can I determine expansion or shrinkage when the window is resized?
I wonder how I can tell when the window is resized if the user expands or shrinks the view port?
One general idea would be like this, but I'm not sure how to implement it:
$(window).resize(function() {
var initialWidth = ...;
var initialHeight = ...;
var finalWidth = ...;
var finalHeight = ...;
if ((initialWidth < finalWidth) || (initialHeight < finalHeight)) {
return 'expand';
} else {
return 'shrink';
}
});
thank
+3
source to share
1 answer
You may try:
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;
});
+2
source to share