2

This is my code here it works fine on browser but not on mobile, am not that expert in jQuery so if there is any mistake, do forgive me.ty

var width = $(window).width(), height = $(window).height();
            $(window).on('resize', function() {

                if($(window).width() != width && $(window).height() != height)
                {
                    var width = $(window).width(), height = $(window).height();

                    //do something here;
                }
            });
Jithin Raj P R
  • 6,667
  • 8
  • 38
  • 69
  • Many mobile browsers (at least Chrome and Safari) hide or show or resize their menu bar when scrolling up or down, which effectively resizes the `window`. – xaggre Mar 06 '17 at 13:05
  • First of all thank you for your replay...So thats the issue am facing, in your opinion will this be avoided using only "width of the Window" as the trigger?@MyronHöster – Jithin Raj P R Mar 07 '17 at 12:27
  • Possible duplicate of [javascript resize event on scroll - mobile](http://stackoverflow.com/questions/9361968/javascript-resize-event-on-scroll-mobile) – sazzad Apr 23 '17 at 11:33
  • ok Got it, ty for your tip. Actually i used the code on the answer and it worked like a charm. TY for you listening to my Q – Jithin Raj P R Apr 27 '17 at 10:37

1 Answers1

7

I found out the answer in StackOverflow itself link of the solution. it's the answer by sidonaldson that helped me solve my issue.ty

Here is the code

var cachedWidth = $(window).width();
    $(window).resize(function(){
        var newWidth = $(window).width();
        if(newWidth !== cachedWidth){
            //DO RESIZE HERE
            cachedWidth = newWidth;
        }
    });
Jithin Raj P R
  • 6,667
  • 8
  • 38
  • 69