0

I want to know how i can disable scroll on (Window), but allow scrolling on text area. I tried this code but it totally disable everything:

$('html, body').css({
    overflow: 'hidden',
    height: '100%'
});
2
  • 1
    Can you provide a fiddle of this? Commented Oct 20, 2017 at 12:27
  • Maybe, you could find this question useful : Hiding the scrollbar on a HTML page Commented Oct 20, 2017 at 12:29

3 Answers 3

1

A setup like this might work for you?

<div class="container">
    <h1>heading</h1>
    <div class="scrollable">
        Text that will scroll. Text that will scroll. Text that will scroll. Text that will scroll. Text that will scroll. Text that will scroll. Text that will scroll. Text that will scroll. Text that will scroll.
    </div>
</div>

<style>
.container {height: 110px; width:100px; overflow:hidden;}
.scrollable {overflow:auto;width:100%;height:30px}
</style>

here is a codepen https://codepen.io/idlethumbs/pen/WZmEgQ

Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

$('html, body').css({
    overflow: 'hidden',
    height: '100%'
});

And in the text area add:

style="overflow:scroll;"

Comments

0

I write this for mobile web page...

Prepare a function to prevent scroll event

var touchScroll=function(event){event.preventDefault();};

Binding to some element, when you touch this element, make document not to scroll.

$('#your_element').click(function()
{$(document).bind('touchmove', touchScroll)});
document.ontouchmove=function(e){e.preventDefault();} //Add this for take effect in iOS Safari, confirmed on iOS 12.x

Unbind

$('#your_element').click(function()
{$(document).unbind('touchmove', touchScroll)});
document.ontouchmove=function(e){return true;} //Restore event in iOS Safari

Hope this helps~

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.