在滚动上显示控件

时间:2014-02-06 13:53:54

标签: jquery

当用户向下滚动超过页面的一半并在向上滚动时隐藏它时,是否有一种简单的方法可以在页面底部显示窗格。如果他们不想再次看到它,他们也应该能够关闭它。

这是我到目前为止所尝试的:

$(window).scroll(function() {
        if($(this).scrollTop() > 200) {
            $('#note').fadeIn();
        } else {
            $('#note').fadeOut();
        }
});

$("#note").click(function() {
        $("#note").fadeOut("slow");
        return false;
});

http://jsfiddle.net/Zvx8h/1/

1 个答案:

答案 0 :(得分:0)

首先使用position:fixed将您的小组置于底部:

#note{
  display:none;
  position:fixed;
  bottom:0;
  right:0;
}

然后点击后删除窗口的scroll事件:

$("#note").click(function() {
    $("#note").fadeOut("slow");
    $(window).off('scroll');
});

检查此演示http://jsfiddle.net/Zvx8h/2/