jquery onclick事件鼠标滚动

问题描述 投票:0回答:1
        $header.each( function() {

            var t       = jQuery(this),
                button  = t.find('.button');

            button.click(function(e) {

                t.toggleClass('hide');

                if ( t.hasClass('preview') ) {
                    return true;
                } else {
                    e.preventDefault();
                }

            });

        });

在上面的代码中,我想将button.click事件更改为鼠标滚动。

即我想删除按钮,并希望直接在鼠标滚动上的CSS效果。

jquery css
1个回答
0
投票

所以这是完整的答案。要收听第一个滚动,您可以这样做:

$(document).ready(function() {
    var firstScroll = false;
    $(window).scroll(function() {
        if(!firstScroll) {
            firstScroll = false;
            // Put your code here..
        }
    });
});

这将始终监听滚动事件,但只在第一个滚动上运行您的代码。优雅的方法是在运行代码后分离监听器,这将导致只运行一次然后停止监听。

$(document).ready(function() {
    $(window).scroll(function() {
        // Put your code here..
        $(window).off("scroll");
    });
});

我希望有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.