Javascript resize events on scroll - mobile

I am trying to create a website for mobile devices. I have a β€œresize” event tied to a window that should rearrange the elements when the mobile device is rotated (portrait ↔ landscape). On iPhone and Samsung Galaxy SII, the event fires when I scroll down the page, and this is bad.

Any suggestions?

+19
javascript events resize mobile
Feb 20 2018-12-12T00:
source share
2 answers

Use the onOrientationChange event and the window.orientation property.

Also see this answer .

Here is a link to the test page .

+6
Feb 20 '12 at 13:35
source share

Load the width of the viewport, and when resizing, return false if the width remains the same.

A small jQuery snippet:

  var cachedWidth = $(window).width(); $(window).resize(function(){ var newWidth = $(window).width(); if(newWidth !== cachedWidth){ //DO RESIZE HERE cachedWidth = newWidth; } }); 
+38
Jun 19 '14 at 4:48
source share



All Articles