Reputation: 11750
I wonder how can I detect, on window resize, if user extends or shrinks the view port?
One general idea would be this one but I am 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 you
Upvotes: 3
Views: 947
Reputation: 1891
You can try it:
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;
});
Upvotes: 2