如何通过滚动向上和向下移动元素时将元素停在页脚行

时间:2018-07-25 13:01:33

标签: javascript jquery html css

我添加了一个随着滚动向上和向下移动的元素,但问题是它与页脚合拢。下面是我正在使用的示例代码

put movies/movie/1
{
  "weighted_description": [
    {"tag": "romance", "weight": 0.4},
    {"tag": "comedy", "weight": 0.1},
    {"tag": "Sophie Starring", "weight": 0.2},
    {"tag": "James Actor", "weight": 0.1},
    {"tag": "90's", "weight": 0.05},
    {"tag": "New York", "weight": 0.05}
  ]
}

示例HTML代码

$(document).ready(function () {
  var top = $('#comment').offset().top - parseFloat($('#comment').css('marginTop').replace(/auto/, 0));
  $(window).scroll(function (event) {
    // what the y position of the scroll is
    var y = $(this).scrollTop();

    // whether that's below the form
    if (y >= top) {
      // if so, ad the fixed class
      $('#comment').addClass('fixed');
    } else {
      // otherwise remove it
      $('#comment').removeClass('fixed');
    }
  });
});

1 个答案:

答案 0 :(得分:0)

我通过给bottom:somevalue来解决它,并且现在可以正常工作了