问题描述
我有一个设置为溢出的 div:scroll;.我得到了我想要的滚动条.但是,当使用鼠标滚轮滚动 div 时,它会在到达 div 内容的顶部或底部时滚动页面的其余部分.
I have a div which is set to overflow:scroll;. I get scrollbars which is what I want. However when scrolling the div with the mousewheel it scrolls the rest of the page when it reaches the top or bottom of the div's content.
如何根据悬停的内容仅滚动 div 或整个页面?
How can I scroll only the div or the entire page based on what's hovered ?
推荐答案
首先我不认为你可以覆盖滚动事件.所以这就是我要做的.我不知道 jquery,但这里有一些直接的 javascript.
First I don't think you can override the scroll event. So here is what I would do. I don't know jquery but here is some straight javascript.
document.getElementById('scrollDiv').onmouseover=function(){
document.getElementByTagName('body')[0].style.overflow='hidden';
}
document.getElementById('scrollDiv').onmouseout=function(){
document.getElementByTagName('body')[0].style.overflow='';
}
显然你可以稍微调整一下,但这是基本的想法.此外,如果您需要,您可以执行其他测试用例.就像如果 div 有焦点然后做同样的事情.取决于您的设置.
Obviously you could tweak this a little, but this is the basic idea. Also, if you need to you could do other test cases. Like if the div has focus then do the same thing. Depends on your setup.
这篇关于如何防止鼠标在悬停元素之外滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!





大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)