简体   繁体   English

在移动Safari中向下滚动时执行操作

[英]Perform action when scrolling down in mobile Safari

In the site that I'm building, I have it set up where when the user scrolls down the header fades to zero opacity. 在我正在构建的网站中,我对其进行了设置,当用户向下滚动时,页眉逐渐淡化为零。 I'd like the same thing to happen in Mobile Safari but the JS I'm using doesn't seem work at all on mobile. 我希望在Mobile Safari中发生相同的事情,但是我正在使用的JS在移动设备上似乎根本不起作用。

function EasyPeasyParallax() {
   scrollPos = $(document).scrollTop();
    $('#header').css({
        'opacity': 1-(Math.min(scrollPos/70,1))
    });
};



 $(function(){
    $('body').bind('mousewheel',EasyPeasyParallax);
});

Looks like this actually is possible! 看起来这实际上是可能的!

http://wicky.nillia.ms/headroom.js/ http://wicky.nillia.ms/headroom.js/

You should use .on('scroll',EasyPeasyParallax) . 您应该使用.on('scroll',EasyPeasyParallax) However, this won't work in mobile Safari, because mobile Safari only triggers the scroll event, when the scrolling has finished. 但是,这在移动Safari中不起作用,因为移动Safari仅在滚动完成后才触发滚动事件。 So I believe there currently is no easy way to achieve this behavior in mobile safari. 因此,我相信目前尚没有简便的方法可以在移动Safari中实现此行为。

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

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