100px之后的jQuery Scroll功能 [英] jQuery Scroll function after 100px

查看:147
本文介绍了100px之后的jQuery Scroll功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用此脚本:

<script>
$(function() {
    $(window).scroll(function(){
        $('#Your element id').slideUp('slow');
    });
});     
</script>

是否可以在用户滚动100px或更多后执行操作?

Is it possible only to perform the action after the user has scrolled 100px or more?

推荐答案

你需要如上所述的scrollTop。包含'else'函数也是明智之举,这样当你向后滚动到顶部时,切换元素会再次被隐藏。因此:

You do need scrollTop as said. It would be wise to include an 'else' function as well, so that when you scroll back to the top the toggled element gets hidden again. As such:

$(document).ready(function() {
    $('#scrollDiv').hide();
    $(window).scroll(function() {
        if ($(document).scrollTop() > 100) {
            $('#scrollDiv').fadeIn('slow');
        }
        else {
            $('#scrollDiv').fadeOut('slow');
        }
    });
});​

这是一个快速的 jsfiddle

这篇关于100px之后的jQuery Scroll功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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