Turn off all page scrolling on website

Is there a way to completely eliminate scrolling on a webpage?

Currently, I have implemented the following CSS:

html, body { overflow:hidden; }

However, this solution does not effectively disable scrolling on iOS devices. In fact, it still allows scrolling if you hold the mouse wheel and drag it down, which is not ideal.

Is there a foolproof method to disable all scrolling options on any device and then later re-enable it?

Answer №1

I encountered the same issue and was able to resolve it with the following solution:

var disableScroll = false;
var scrollPos = 0;
function stopScroll() {
    disableScroll = true;
    scrollPos = $(window).scrollTop();
}
function enableScroll() {
    disableScroll = false;
}
$(function(){
    $(window).bind('scroll', function(){
         if(disableScroll) $(window).scrollTop(scrollPos);
    });
    $(window).bind('touchmove', function(){
         $(window).trigger('scroll');
    });
});

The touch move event is bound to the window since the window scroll event is not triggered until the touch move is completed. This results in a smoother experience on iOS devices.

While this solution may not be perfect and allows for page 'throwing,' it will return to the desired position once the throw is complete. iOS browsers tend to strip out certain events for performance reasons, and functions like setTimeout and setInterval do not fire during page throws.

For a demonstration, you can visit http://jsfiddle.net/8T26k/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Updating the background of a specific div element by retrieving data from an SQL database

I have a unique situation where I have a div element with the property set to runat="server" and an ID assigned to it. I am attempting to dynamically set the background image for this specific div from a MySQL database where the path URL is stored in a r ...

How to efficiently transfer data between PHP and Javascript using ajax?

Struggling greatly with the ajax function within the jQuery library. As a beginner in jQuery, ajax, and php, I am currently engaged in a school project that involves creating a game-like environment where a 10x10 table generates numbers, selects a cell aut ...

Incorporate a class into a link within the wp_list_pages function

I've been experimenting with creating a hover effect on list items using the wp_list_pages() function in my Wordpress theme. Despite my efforts, I've hit a roadblock in getting the hover effect to work properly. As a beginner in web development, ...

What is the method for updating the value of the Sass variable in Angular 4?

Within the file app.component.scss, there is a variable named $color that has been set to 'red'. What steps can be taken within the file app.component.ts in order to access this variable and change its value to 'green'? ...

Upon inserting Node 5, an error with the code EINVALIDTYPE occurred in npm

Recently, after I upgraded to Node 5, I've been encountering an error in the terminal every time I try running anything with npm. npm -v: 2.14.12 Desperately attempting to update npm to the latest version: MacBook-Pro-de-MarceloRS:promo-auto-loan ...

How can we restrict a textbox to only accept alphanumeric characters using solely HTML code?

Imagine a scenario where you have a textbox and your goal is to allow only alphanumeric characters (case insensitive). You've already achieved this using javascript and regex.test(), but now you're wondering if there is a simpler way to implement ...

Use hyphens instead of spaces in angular js data binding

<form role="form" method="POST" action="{{ url('/roles/save') }}" data-ng-app=""> <div class="form-group"> <label>Page-Title:</label> <input type="text" required value="" data-ng-model="title" name="pag ...

Cover the entire section with an image

I'm aiming to achieve a similar layout like this (using tailwind) : https://i.stack.imgur.com/G0oti.png Here's the current setup: <section class="bg-juli-white pt-24"> <div class="max-w-6xl mx-auto flex flex-col" ...

What steps are needed to resolve the issue of inserting data into a database using Sequelize with Node Express and M

I am currently in the process of developing a straightforward registration form that will lead to additional CRUD operations using node.js. So far, I have set up the MySQL database and completed the modeling and connection with Sequelize. I have also desi ...

Any tips on silencing webpack's constant nagging about the "Critical dependency: require function is used in a way..." warning message?

My immediate goal is to resolve this warning. However, it seems that a different approach may be necessary. I have developed an npm library for date/time functions with most of the code being general-purpose and compatible with both Node.js and web browse ...

Do designers often manually adjust elements using media queries when working with Bootstrap?

Is it common practice to directly invoke media queries in order to manually adjust the layout of elements when using Bootstrap? In other words, if I have a custom element that I need to display or position in a specific way, is it acceptable to call the m ...

Obtaining a 16-bit integer from the response of an LWIP server

On the server side, I have implemented a loop that takes a 16-bit integer ranging from 0 to 639 and splits it into two 8-bit characters to populate a buffer of 1280 Bytes. The buffer is then sent via TCP-IP to the client. .c unsigned int data2[1000]; ch ...

Is there a way to display the button just once in a map function while still retaining access to the iteration value?

Utilizing formik within material-ui for a form has been quite productive. I've implemented a map function to print text fields and managed to display the Submit button only once by targeting the index. However, there's an issue when attempting to ...

Display a webpage in thumbnail form when hovering the mouse over it

I'm in the process of creating a website that contains numerous sub-pages. I want to display all the links on a single page and when a user hovers over a link, I want to show a thumbnail of the corresponding webpage within a tooltip. I've experi ...

Having trouble accessing Google Spreadsheets in CSV format but unable to do so in JSON format?

I have been experimenting with Google's Visualization API to retrieve data from a specific row in a Google Spreadsheet based on a given string in the column labeled "key". When I run the following code, the success function is triggered and I receive ...

Expand the width of the image gradually until it reaches its initial size within a flexible DIV container

I am working with a <div> container that occupies 80% of the screen on a responsive page. Within this <div>, I am attempting to display an image that is sized at 400 x 400 pixels. My objective: As the screen width increases: The <div> ...

Conceal the form node's visibility upon initial inspection

My goal is to understand how the "add a comment" feature on Stack Overflow works by examining the code in three sections: footnote-list, footnote-form, and add-form-link. footnote-list footnote-form add-form-link <div class="col-md-12 footnotes"> ...

The requested URL /api/users/register does not exist. Error 404

While creating a money manager application utilizing the MERN Stack, I encountered an issue with posting data to the database. Whenever I click on the register button, an error is thrown stating that it Cannot POST /api/users/register. Despite setting up a ...

What could be causing my tabs to shift to the vertical side when using large, larger, and wide screens?

In my previous research, I came across a question similar to mine: Pure CSS accordion not working within CSS tabs. The solution mentioned works perfectly on monitors of any size, but the difference lies in the use of the a element. In their code, setting t ...

Do ES6 features get transpiled into ES5 when utilized in TypeScript?

After implementing ES6 features such as template strings, arrow functions, and destructuring in a TypeScript file, I compile the code to regular JavaScript... Does the TypeScript compiler also compile the ES6 syntax, or do I need to utilize another compil ...