[英]Disable scroll only by JS
我有两个div,但是当我在其中一个上隐藏滚动条时,这两个菜单上都会出现bug,因此我需要在CSS中看到溢出。 但是只需禁用js滚动即可。 专门用于id为chatcontent的 div。
您可以通过以下javascript通过id'chatcontent'为元素指定溢出样式:
// Disables the overflow behaviour for chatcontent
function disableOverflowForChatcontent() {
document.getElementById('chatcontent').style.overflow = 'hidden';
}
// Resets the overflow behaviour for chatcontent
function resetOverflowForChatcontent() {
document.getElementById('chatcontent').style.overflow = '';
}
理想情况下,您将定义CSS类,通过它们可以控制overflow
行为。 假设您有以下CSS,那么您的javascript最好写成:
CSS:
.overflow-none {
overflow:hidden;
}
JS:
// Disables the overflow behaviour for chatcontent
function disableOverflowForChatcontent() {
document.getElementById('chatcontent').classList.add('overflow-none');
}
// Resets the overflow behaviour for chatcontent
function resetOverflowForChatcontent() {
document.getElementById('chatcontent').classList.remove('overflow-none');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.