event.preventDefault();在Firefox中不停止鼠标滚轮 [英] event.preventDefault(); not stopping mousewheel in Firefox

查看:156
本文介绍了event.preventDefault();在Firefox中不停止鼠标滚轮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在jquery中使用鼠标滚轮来增加div的数量,该数字可以正确增加,但是在Firefox中滚动不会停止.

I am using the mousewheel in jquery to increase the number of a div, the number increases correctly but the scroll is not stopped in Firefox.

$(document).ready(function(){

    $('#test').bind('mousewheel DOMMouseScroll', function(event){

        var currentValue = parseInt($('#test').text(),10),
            newValue = currentValue + 1;

        $('#test').text(newValue);    
        event.preventDefault();
    });
});

提琴: http://jsfiddle.net/rHVUn/

小提琴使用标准的鼠标滚轮检测,但是我也使用了Brandon Aaron的鼠标滚轮插件,并且存在相同的问题.

The fiddle uses the standard mousewheel detection, but I have also used Brandon Aaron's mousewheel plugin and it has the same problem.

删除用于更新div文本的行(我也尝试过html())可以解决此问题,但这是代码的关键部分,因此无法删除.

Removing the line that updates the text (I have also tried html()) of the div resolves the issue, but this is a crucial part of the code and cannot be removed.

有人知道如何解决此问题吗?

Does anyone know how to resolve this issue?

谢谢

更新:我发现仅当鼠标直接位于文本上方时才会出现问题,如果鼠标位于文本框内但不在文本上方(填充内),则滚动停止

Update: I have found the problem only occurs when my mouse is positioned directly over the text, if my mouse is within the box but not over the text (within the padding) the scroll is stopped

推荐答案

我已经找到解决问题的方法,它可能不是解决问题的最佳方法,但它确实有效.

I have found a solution to my problem, it may not be the best way to do this but it works.

我发现问题仅在滚动期间鼠标直接位于文本上方时发生,因此我添加了一个叠加元素并将其用作鼠标滚轮触发器.

I found the problem only occurs when my mouse is positioned directly over the text during the scroll, so I added an overlaying element and use that as the mousewheel trigger.

小提琴: http://jsfiddle.net/rHVUn/9/
(不需要背景色)

Fiddle: http://jsfiddle.net/rHVUn/9/
(The background colour is not needed)

这篇关于event.preventDefault();在Firefox中不停止鼠标滚轮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆