I need to make a smooth twist to the unit on mobile devices, but I do not know how to implement the check. I hope for help. I do it, but it does not work.

$(window).resize(function() { if ($(window) <= "600") { $('.ionTabs__head li').on('click', function() { $('html,body').animate({ scrollTop: $('.content-body').offset().top }, 200); }); } }); 

  • That is, that the script worked if the resolution is less than 600, and turned off if the resolution exceeds the permissible figure. - Alexander

1 answer 1

Something like this should work ...

 var ori = window.orientation, width = (ori===90 || ori===-90) ? screen.height : screen.width; $(window).on('resize load', function () { ori = window.orientation, width = (ori===90 || ori===-90) ? screen.height : screen.width; }); $('.ionTabs__head li').on('click', function() { if (width < 600){ $('html,body').animate({ scrollTop: $('.content-body').offset().top }, 200); } }); 
  • Works exactly to resize. If the window is stretched more than 600 pixels in width, and then narrowed to a value less than 600, it stops working. - Alexander
  • @ Alexander means that something is wrong, what are you testing, a device? - PavelBY Nov.
  • I note: it works on mobile devices and emulsions, changing boundaries on the desktop - of course, orientation won't work .... - PavelBY
  • Yes thank you. On mobile works. - Alexander