简体   繁体   English

取消Jquery中的wheel事件

[英]Unbind wheel event in Jquery

I want to design my website using skrollr.js and fullpage.js libraries. 我想使用skrollr.js和fullpage.js库设计我的网站。 But skrollr uses the value of scrollTop to transform elements that we choose and fullpage.js seems to scroll the page but he just change the top value of the viewport, so ScrollTop doesn't change and skrollr.js is not effective. 但是skrollr使用scrollTop的值来变换我们选择的元素,并且fullpage.js似乎在滚动页面,但是他只是更改了视口的最高值,因此ScrollTop不会改变并且skrollr.js无效。

I looking for some informations and i finally do my own fullpage.js (i tried) : 我在寻找一些信息,最后我做了自己的fullpage.js(我尝试过):

$('.frame').css({
    'height':$(window).height()
});

var active ="section 1";
$(window).bind('mousewheel', function(event) {
    event.preventDefault();
    event.stopPropagation();

    if (event.originalEvent.wheelDelta >= 0) {
        if(active=="section 2"){
            $("html,body").stop().animate({scrollTop: 0}, 1000);
            active="section 1";
        }
        else if(active=="section 3"){
            $("html,body").stop().animate({scrollTop:  $(window).height()}, 1000);
            active="section 2";
        }
    }
    else {
        if(active=="section 1"){
            $("html,body").stop().animate({scrollTop: $(window).height()}, 1000);
            active="section 2";
        }
        else if(active=="section 2"){
            $("html,body").stop().animate({scrollTop: $(window).height()*2}, 1000);
            active="section 3";
        }
    }
});

I have 3 div .frame 我有3 div .frame

But when i'm on the first div and i scroll down, my viewport go to the third because i bind the event more than one time. 但是当我在第一个div上并且向下滚动时,我的视口转到了第三个div,因为我多次绑定该事件。

I want to bind one event, scroll and unbind the event for maybe 1 sec. 我想绑定一个事件,滚动并取消绑定该事件大约1秒钟。

Now fullPage.js includes an option called scrollBar since version 2.4.4 which uses the scrollTop feature and therefore works as expected with plugins such as the one you mention or even parallax. 现在,fullPage.js从2.4.4版开始包含一个名为scrollBar的选项,该选项使用scrollTop功能,因此可以与您提到的插件甚至视差插件一起使用。

It is set to false by default, so you would have to turn it on when initializing fullPage.js. 默认情况下将其设置为false,因此在初始化fullPage.js时必须将其打开。

Check this living example . 检查这个生动的例子

scrollBar: (default false). scrollBar :(默认为false)。 Determines whether to use scrol bar for the site or not. 确定是否对网站使用滚动条。 In case of using scroll bar, the autoScrolling functionallity will still working as expected. 如果使用滚动条,则自动滚动功能仍将按预期工作。 The user will also be free to scroll the site with the scroll bar and fullPage.js will fit the section in the screen when scrolling finishes. 用户还可以使用滚动条自由滚动站点,并且在滚动完成时fullPage.js将适合屏幕中的该部分。

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

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