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
           });
       };
   });
});
2
  • 1
    Your code is not readable, please format it. Commented Nov 25, 2015 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});};});}); Commented Nov 25, 2015 at 17:51

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.