I found that the $(window).resize() will be triggered when you scroll up/down the website on a mobile device. To prevent this happens, we could add a checking on the screen width.
var width = $(window).width(); $(window).resize(function(){ if ($(window).width() != width) { // Only action on screen width change width = $(window).width(); } });
Done =)
Reference: StackOverflow – javascript resize event on scroll – mobile
Yes, exactly! The reason this happens in Chrome seems to be the browserbar that dis- and reappears on scroll. This triggers the resize event. Tracking the width like in the code above prevents triggering the resize event. Thank you!
LikeLike
Do you have the same code but in plain javascript? Cheers.
LikeLike