0

我正在尝试对向下滚动页面时弹出的 div 创建最小化效果。一切都很好,只有一个问题。如果最小化功能完成并且我向上滚动页面,它将恢复其原始值。我希望它在单击最小化按钮并向上滚动一点后,它应该保持最小化并且不恢复。

这是我正在使用的

$(function () {
    $(window).scroll(function () {
        var height = $(window).height() /2;
        if ($(this).scrollTop() >= height) {
            $("#box").animate({'bottom':'0px'},300);
        }
        else {
            $("#box").stop(true).animate({'bottom':'-150px'},100);
        }
}); });

$('.minimize').toggle(function() {
  $('#box').animate({'bottom':'-80px'},200);},
  function() { $('#box').animate({'bottom':'0px'},200);
});

检查演示小提琴

4

1 回答 1

1

我同意Machiee 的评论。

你可以这样做:

$(function () {
    $(window).scroll(function (e) {
        if($('#box').hasClass('minimized'))
            return;
        var height = $(window).height() /2;
        if ($(this).scrollTop() >= height) {
            $("#box").animate({'bottom':'0px'},300);
        }
        else {
            $("#box").stop(true).animate({'bottom':'-150px'},100);
        }
}); });

$('.minimize').toggle(function() {
  $('#box').animate({'bottom':'-80px'},200);
  $('#box').addClass('minimized');
},
  function() { $('#box').animate({'bottom':'0px'},200);
              $('#box').removeClass('minimized');
});

检查演示小提琴

于 2014-01-16T15:23:33.460 回答