I am looking for an event listener, what works like jQuery's .resize()
, but only fires when the resized object (talking about the window) is resized in x axis, or both, but not in only y axis. - So basically it will only listen the resize events of the width.
You can save the width of the browser on a window load in variable. Example:
var w = 0;
$( window ).load( function(){
w = $( window ).width();
});
$( window ).resize( function(){
if( w != $( window ).width() ){
//Do something
w = $( window ).width();
}
});
How about using like this?
var w = $(window).width();
$(window).resize(function(){
if ($(window).width()==w) return;
w = $(window).width();
// ... your code
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With