且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

防弹鼠标滚轮

更新时间:2023-12-05 15:58:22

如何使用setTimeout控制事件的触发-如:

How about using setTimeout to control the firing of events - as:

$("div").html((new Array(1000)).join(" test")).on("mousewheel DOMMouseScroll MozMousePixelScroll", function()
{
    if (!$(this).data('flag'))
    {
        var self = this;
        $(this).data('timeout', window.setTimeout(function()
        {
            $(self).data('flag', false);
        }, 500));

        $(this).data('flag', true);

        console.log('here');
    }
});

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