How to disable scroll / scrolling on iOS devices (iPad, iPhone, Mac) with user-controlled toggle (enable / disable)

Sebastian Alsina

In reviewing the many questions and answers on this topic on StackOverflow, none of the solutions provided worked reliably. All CSS, JavaScript, jQuery and hybrid solutions had at least one deficiency that prevented the scroll from disabling and/or toggling effectively.

I've also searched the web high and wide and have not found a good answer.

So far I have this function:

function toggleScroll(btn, item) {
 $(btn).click(function() {
  $(item).toggleClass("noscroll");
 });
}

...which will add a overflow: hidden; to any class I want onclick, and remove it on second click.

The thing is, this code doesn't work with iOS devices.

How could I make this work with iOS devices?

Ideally, I would prefer a pure CSS solution. But I understand that this may not be possible, especially the toggle component.

Any JavaScript or jQuery solution would be fine, as well.

Thanks in advance!

Michael Benjamin

Disable Scroll / Scrolling on iOS Devices (iPad, iPhone, Mac) with jQuery

I think this gets you close to what you want. The only issue may be the toggle, which is two buttons (Enable and Disable). If you want to make the toggle a single button, maybe you can post a separate question or somebody else can improve upon this answer. (I'm mostly an HTML / CSS / PHP guy. I'm somewhat new to JS).

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');
    });
});

credit: https://stackoverflow.com/a/17597303/3597276


Disable Scroll / Scrolling on iOS Devices (iPad, iPhone, Mac) with CSS

For a pure CSS solution to disable scrolling on iOS devices try these options:
(Of course, these have no toggle.)

html, body {
    position: fixed;
}

html, body {
    position: relative;
    overflow: hidden;
}

body {
    position: fixed;
    overflow: hidden;
}

body {
    position: fixed;
    height: 100%;
    overflow: hidden;
    width: 100%;
}

Here are some of the posts and articles I read on this issue.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to disable inertial scrolling on body for iOS browsers?

From Dev

Disable horizontal scrolling on mobile devices (or with scroll-click)

From Dev

How to disable and enable the scrolling on android ScrollView?

From Dev

iOS UITableView how to disable scroll to bottom bouncing

From Dev

Disable / Enable Scroll for ListView in android

From Dev

Disable iPad horizontal scrolling

From Dev

Disable scroll, animation, then enable scroll again

From Dev

How do I disable landscape orientation in iPhone but keep it enabled on iPad?

From Dev

Crossbrowser solution for disable/enable scroll

From Dev

Disable uitableview disable reuse when scrolling in iOS

From Dev

How does Amazon SNS disable/re-enable devices when notifications are changed in iOS Settings?

From Dev

Safari - IPAD - Disable bounce (no scroll) without -webkit-overflow-scrolling

From Dev

Nativescript: how to programmatically disable / enable ScrollView scrolling?

From Dev

how to enable and disable dm verity on android devices?

From Dev

How to disable and enable scrolling in LazyColumn/LazyRow in Jetpack Compose?

From Dev

Disable scroll on mobile devices

From Dev

disable two finger scrolling on ipad

From Dev

Disable iPad horizontal scrolling

From Dev

JButton toggle disable and enable ItemListener

From Dev

Disable scroll, animation, then enable scroll again

From Dev

How to automatically disable and enable scroll for pre tag

From Dev

How to disable/enable/toggle touchpad in a Dell laptop

From Dev

How does Amazon SNS disable/re-enable devices when notifications are changed in iOS Settings?

From Dev

How to toggle enable/disable input field based on radio button

From Dev

Safari - IPAD - Disable bounce (no scroll) without -webkit-overflow-scrolling

From Dev

How to disable rotation animation for iPhone and iPad devices

From Dev

How to enable and disable toast with toggle button in Android?

From Dev

How to enable and disable a button with toggle

From Dev

Disable automatic scroll in UICollectionView if user is scrolling

Related Related

  1. 1

    How to disable inertial scrolling on body for iOS browsers?

  2. 2

    Disable horizontal scrolling on mobile devices (or with scroll-click)

  3. 3

    How to disable and enable the scrolling on android ScrollView?

  4. 4

    iOS UITableView how to disable scroll to bottom bouncing

  5. 5

    Disable / Enable Scroll for ListView in android

  6. 6

    Disable iPad horizontal scrolling

  7. 7

    Disable scroll, animation, then enable scroll again

  8. 8

    How do I disable landscape orientation in iPhone but keep it enabled on iPad?

  9. 9

    Crossbrowser solution for disable/enable scroll

  10. 10

    Disable uitableview disable reuse when scrolling in iOS

  11. 11

    How does Amazon SNS disable/re-enable devices when notifications are changed in iOS Settings?

  12. 12

    Safari - IPAD - Disable bounce (no scroll) without -webkit-overflow-scrolling

  13. 13

    Nativescript: how to programmatically disable / enable ScrollView scrolling?

  14. 14

    how to enable and disable dm verity on android devices?

  15. 15

    How to disable and enable scrolling in LazyColumn/LazyRow in Jetpack Compose?

  16. 16

    Disable scroll on mobile devices

  17. 17

    disable two finger scrolling on ipad

  18. 18

    Disable iPad horizontal scrolling

  19. 19

    JButton toggle disable and enable ItemListener

  20. 20

    Disable scroll, animation, then enable scroll again

  21. 21

    How to automatically disable and enable scroll for pre tag

  22. 22

    How to disable/enable/toggle touchpad in a Dell laptop

  23. 23

    How does Amazon SNS disable/re-enable devices when notifications are changed in iOS Settings?

  24. 24

    How to toggle enable/disable input field based on radio button

  25. 25

    Safari - IPAD - Disable bounce (no scroll) without -webkit-overflow-scrolling

  26. 26

    How to disable rotation animation for iPhone and iPad devices

  27. 27

    How to enable and disable toast with toggle button in Android?

  28. 28

    How to enable and disable a button with toggle

  29. 29

    Disable automatic scroll in UICollectionView if user is scrolling

HotTag

Archive