简体   繁体   English

为什么mousewheel在chrome中无法工作,而在Firefox中却无法工作

[英]why does mousewheel work in chrome but no in firefox

I currently am using CSS to scroll up and down a popup page by just using the mousewheel, but I can't get it to work in FireFox. 我目前仅使用鼠标滚轮即可使用CSS上下滚动弹出页面,但无法在FireFox中使用它。 It currently works in Chrome for some reason just using overflow-x:hidden; 由于某种原因,它目前只能在Chrome中运行,只是使用了overflow-x:hidden;。 and overflow-y:auto;. 并溢出-y:auto;。

I've tried using the jQuery Mousewheel Plugin jquery.mousewheel.min.js to get a page to scroll up and down without scrollbars on the side, but alas, I can't get it to work. 我已经尝试使用jQuery Mousewheel插件jquery.mousewheel.min.js来使页面上下滚动,而侧面没有滚动条,但是,我无法使其正常工作。 Is there something else Firefox needs to be able to scroll up and down a page just using the mousewheel? Firefox是否还需要其他功能才能仅使用鼠标滚轮上下滚动页面? Either CSS, Javascript or jQuery? CSS,JavaScript还是jQuery?

HTML HTML

<div class="test">
   <div class="inner">blah blah blah
   </div>
</div>

CSS CSS

.test{
display:inline-block;
overflow-x:hidden;
overflow-y:auto;
margin:0 auto;
}

.inner{
float:left;
overflow-x:hidden;
overflow-y:auto;
}

If you're talking about handling mousewheel event in plain JavaScript, I believe Firefox has a different name for it: DOMMouseScroll so to catch it universally you can do something like: 如果您正在谈论使用纯JavaScript处理鼠标滚轮事件,我相信Firefox可以使用一个不同的名称: DOMMouseScroll因此要通用捕获它,您可以执行以下操作:

if (document.addEventListener) {
    document.addEventListener("mousewheel", MouseWheelHandler, false);
    document.addEventListener("DOMMouseScroll", MouseWheelHandler, false);
}
else {
    document.attachEvent("onmousewheel", MouseWheelHandler);
}   

function MouseWheelHandler(e) {

    var e = window.event || e;
    var delta = e.wheelDelta

    if (delta < 0) {
        // Do stuff when wheel is scrolled down
    } else {
        // Do stuff when wheel is scrolled up    
    }
}

You mentioned that you have tried using the jQuery mousewheel plugin, but you haven't provided any JavaScript in your post. 您提到您尝试使用jQuery mousewheel插件,但您的帖子中未提供任何JavaScript。 Are you trying to programmatically (using DOM event listeners) scroll an element? 您是否正在尝试以编程方式(使用DOM事件监听器)滚动元素? If so, note that Chrome only recently added support for the standard 'wheel' event ( https://code.google.com/p/chromium/issues/detail?id=227454 ) so you may have to use the nonstandard 'mousewheel' event. 如果是这样,请注意Chrome仅在最近才添加了对标准'wheel'事件的支持( https://code.google.com/p/chromium/issues/detail?id=227454 ),因此您可能不得不使用非标准的'mousewheel' '事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM