jQuery – Oppress $(window).resize() in when scroll in mobile

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();
  if ($(window).width() != width) {
    // Only action on screen width change
    width = $(window).width();


Done =)

Reference: StackOverflow – javascript resize event on scroll – mobile


2 thoughts on “jQuery – Oppress $(window).resize() in when scroll in mobile”

  1. 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!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.