2017-10-20 81 views
-1

我想知道如何禁用滚动(窗口),但允许滚动文本区域。我想这个代码,但它完全禁止一切:如何使用jquery禁用特定元素的滚动

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

你能提供的这个小提琴? – sjahan

+0

也许,你会发现这个问题很有用:[隐藏滚动条在HTML页面上](https://stackoverflow.com/questions/3296644/hiding-the-scrollbar-on-an-html-page) – 3Dos

回答

0

试试这个:

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

,并在文本区域中添加:

style="overflow:scroll;" 
1

像这样的设置可能适合你吗?

<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> 

这里是codepen https://codepen.io/idlethumbs/pen/WZmEgQ