Home > Web Front-end > JS Tutorial > Disable scrolling of the page

Disable scrolling of the page

韦小宝
Release: 2018-03-14 17:38:56
Original
5451 people have browsed it

This article describes how to prevent page scrolling. If you don’t know about implementing page scrolling prohibition or are interested in implementing page scrolling prohibition, then let’s take a look at this article together. Okay, without further ado, enter Let’s get to the point

Explanation:

1. Here we only summarize the methods of disabling scrolling on the page, which can be used according to actual needs. js can be dynamically controlled.
2. If the mobile terminal can be banned, the PC can naturally be banned, but if the PC can be banned, the mobile terminal may not be banned, so I will focus on the mobile terminal
3. The code demonstrates the zepto I use (you may not be able to use it, but you can definitely understand it)

Preface:

When you are doing mobile development, you will inevitably have the need to disable page scrolling. Today I will summarize the method of disabling page scrolling on the mobile end. I hope there is a scenario that can meet your needs.

1.

 $(document).on('touchmove', function(e){
   e.preventDefault();
 })
Copy after login

2.

  body{    position: fixed;
    //根据需求添加top,left...
  }
Copy after login

3.

  body{    overflow: hidden;    /*height: 100%;*/
  }
Copy after login

4.Click on the page, the page will stop at the clicked position, and then sliding and scrolling will be invalid

//根据这个思路,你也可以去应用于元素的禁止滚动$('body').on('tap', function(e){
  $(this).css('top', ('-' + $(window).scrollTop() + 'px'));
  $(this).css('position', 'fixed');
})
Copy after login

5.Savior method on the mobile side, if If you have relevant development experience, you will find that the previous method magically fails on the mobile terminal, then this method will definitely help you

html,html{  overflow: hidden;  height: 100%;}
Copy after login

Conclusion:

The above is all the content of this article. If you don’t know much about it, you can easily master both sides by yourself!

Related recommendations:

JavaScript implements prohibiting the pull-down rebound effect of WeChat browser

What are the ways to disable page caching

How to use H5 to add a zoom-disable function

jQuery monitoring code scanner prohibits manual input Implementation method

The above is the detailed content of Disable scrolling of the page. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template