Disable scrolling in an iPhone web application?

后端 未结 9 1744
遇见更好的自我
遇见更好的自我 2020-11-27 10:36

Is there any way to completely disable web page scrolling in an iPhone web app? I\'ve tried numerous things posted on google, but none seem to work.

Here\'s my curre

相关标签:
9条回答
  • 2020-11-27 10:58

    Disable:

    document.ontouchstart = function(e){ e.preventDefault(); }
    

    Enable:

    document.ontouchstart = function(e){ return true; }
    
    0 讨论(0)
  • 2020-11-27 11:00
    document.ontouchmove = function(e){ 
        e.preventDefault(); 
    }
    

    is actually the best choice i found out it allows you to still be able to tap on input fields as well as drag things using jQuery UI draggable but it stops the page from scrolling.

    0 讨论(0)
  • 2020-11-27 11:09

    'self.webView.scrollView.bounces = NO;'

    Just add this one line in the 'viewDidLoad' of the mainViewController.m file of your application. you can open it in the Xcode and add it .

    This should make the page without any rubberband bounces still enabling the scroll in the app view.

    0 讨论(0)
  • 2020-11-27 11:09

    This should work. No more gray areas at the top or bottom:)

    <script type="text/javascript">
       function blockMove() {
          event.preventDefault() ;
    }
    </script>
    
    <body ontouchmove="blockMove()">
    

    But this also disables any scrollable areas. If you want to keep your scrollable areas and still remove the rubber band effect at the top and bottom, see here: https://github.com/joelambert/ScrollFix.

    0 讨论(0)
  • 2020-11-27 11:09

    I tried above answers and particularly Gajus's but none works. Finally I found the answer below to solve the problem such that only the main body doesn't scroll but other scrolling sections inside my web app all work fine. Simply set position fixed for your body:

    body {
    
    height: 100%;
    overflow: hidden;
    width: 100%;
    position: fixed;
    }
    
    0 讨论(0)
  • 2020-11-27 11:12

    If you are using jquery 1.7+, this works well:

    $("donotscrollme").on("touchmove", false);
    
    0 讨论(0)
提交回复
热议问题