0

I need to disable scrolling for a specific DIV only for mobile devices

if mobile scrolling disabled else scrolling on

$(function() {
    var offset = $('#sidebar-wrapperleft').offset();
    var topPadding = 0;

    $(window).scroll(function() { 
       if ($(window).scrollTop() > offset.top) { 
           $('#sidebar-wrapperleft').stop().animate({
               marginTop: $(window).scrollTop() - offset.top + topPadding
           });
       } else{
           $('#sidebar-wrapperleft').stop().animate({
               marginTop: 0
           });
       };
   });
});
Sulthan
  • 118,286
  • 20
  • 194
  • 245
  • 1
    Your code is not readable, please format it. – ventsyv Nov 25 '15 at 17:15
  • here is my code: $(function(){var offset=$("#sidebar-wrapperleft").offset(); var topPadding=0;$(window).scroll(function(){if($(window).scrollTop()>offset.top){$("#sidebar-wrapperleft").stop().animate({ marginTop:$(window).scrollTop()-offset.top+topPadding});}else{$("#sidebar-wrapperleft").stop().animate({ marginTop:0});};});}); – user5605193 Nov 25 '15 at 17:51

1 Answers1

1

You need to be aware that "mobile detection" is something that can cause you some headache. If possible, you should rely on screen dimensions to adapt your content.

Mobile detection is problematic because, first of all, what should be considered mobile? Is an iPad mobile or not? As you can see, there are some gray areas in this concept.

There is another thread here (What is the best way to detect a mobile device in jQuery?) where you can find some algorithms based on Browser Agent, and they probably need constant improvement as soon new devices come to market.

Community
  • 1
  • 1
David Rissato Cruz
  • 2,348
  • 1
  • 14
  • 15