Re-calculate Width After Browser Resize
I am running a third party script and it calculates an element's width upon loading. It works great but I have a responsive website and when I re-size the browser the element is no
Solution 1:
Here is what work best
$(window).resize(function() {
if(this.resizeTO) clearTimeout(this.resizeTO);
this.resizeTO = setTimeout(function() {
$(this).trigger('windowResize');
}, 500);
});
$(window).on('windowResize', function() {
console.log($(window).width()); // calculating here
});
reason for having timeout is that window takes some time to get settel the width but classic window.resize
event get triggers before it setteled down
Solution 2:
$(window).on('resize', function(){
//your code to calculate the width
});
Post a Comment for "Re-calculate Width After Browser Resize"