Skip to main content

How to Disable Scrolling on Mobile Devices

 How to Disable Scrolling on Mobile Devices

So let’s start out with setting the viewport meta in the head tags to non-scalable, like so:

<meta name="viewport" content="width=device-width, user-scalable=no">
This will disable the pinch–and–zoom effect as expected, but if you swipe vertically, the viewport will scroll and you’ll end up seeing a random bar at the bottom of the HTML page. That “bar” is the color of the HTML page below your view, which is showing because of what seems like extra padding at the bottom of the HTML. I’m not sure why this happens, but it’s not an issue with your code! This undesired effect happens on both Android and iOS browsers. In addition to how bad it looks, your app or game just got moved out of the viewport slightly!
Luckily, this is an easy fix. If you’re using jQuery, you would use this snippet of code:
$(document).bind('touchmove', function(e) {
 e.preventDefault();
});
Otherwise, if you’re not, here’s the javascript straight-up:
document.addEventListener('touchmove', function(e) {
 e.preventDefault();
}, false);

What is the code doing?

Essentially, you are just adding an event listener for the mobile browser “touchmove” event. When the listener hears that event it fires the anonymous callback function that passes the “touchmove” event as a parameter and prevents its default action. This reasoning is the same for both the jQuery and javascript snippets above, the only differences are syntax.
Like I said, easy to fix, but painful if you are unaware of why that’s happening. It’s one of those bugs that would drive you crazy and kill way too much time if you didn’t know. I hope this little tip on how to disable scrolling on mobile devices was helpful and as always, please share your thoughts and comments below.

Comments

Popular posts from this blog

[Fix] SSL Error or Invalid Security Certificate Problem While Opening Facebook or Other Websites

Today we are going to address a very strange and annoying issue which occurs when you try to open a website using  HTTPS  (Hypertext Transfer Protocol Secure) protocol such as  Facebook, Twitter, Google, etc . The problem occurs in all web browsers whether its  Internet Explorer ,  Google Chrome ,  Mozilla Firefox  or  Opera  but the error messages and problem symptom might differ in different web browsers. Problem Symptom: When you open a HTTPS website such as Facebook, Twitter, etc in your favorite web browser, following things happen: In Google Chrome web browser: The website doesn't open and you see a  red cross on padlock icon  and a  red line through the https://  text in the addressbar with following error message: SSL Error Cannot connect to the real www.facebook.com Something is currently interfering with your secure connection to www.facebook.com. Try to reload this page in a few minutes or after switching to a new network. If you have rece

FAQ's Salesforce Lightning Platform Query Optimizer

This article comprises the FAQs related to salesforce internal platform Query Optimizer.and provides valuable information that will help understand how to improve the performance of SOQL queries. For more information, you may also check this Dreamforce Session . 1. Query Optimizer Q: Does Salesforce have its own SQL optimization logic instead of Oracle's built-in? A: Force.com is a multi-tenant platform. To consider multitenant statistics, the platform has its own SOQL query optimizer that determines optimal SQL to satisfy a specific tenant's request. Q: How frequently generated are the statistics used by the query optimizer? A: Statistics are gathered weekly. Where statistics are not calculated, the optimizer also performs dynamic pre-queries, whose results are cached for 1 hour Q: Is there any way to flush the cache when doing your performance testing so your results are not cached biased? A: Unfortunately not. Queries with selective filters will perform mor

Google Tricks

Google isn't just for hypochondriacs looking up their symptoms or for trying to find a cool new restaurant. By just entering a few simple search terms, you can use Google to help plan and organize your life. It is  amazing . 1.) You can use Google as a timer, just set the time in the search bar as shown here. 2.) Google will also help you calculate your tips. 3.) You can find out what date any holiday falls on. 4.) Google will also find movie release dates for you. 5.) You can find full schedules for your favorite television shows. 6.) Google will also find the songs of your favorite bands. 7.) You can use the search engine to find what books your favorite authors wrote. 8.) It'll look up flight information for you. 9.) Do you know what time the sun rises? It'll tell you. 10.) It'll also give you information on your