本文介绍了如何悬停固定元素,直到它到达某一点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div,我需要固定到屏幕的底部,直到它到达一些点后滚动,停在那里,留下来。

I've got a div which I need to be fixed to the bottom of the screen, until it reaches some point after scrolling and stop there and stay. If a user start scrolling back up - make it fixed again after passing that same point.

有关如何完成这项工作的任何建议吗?

Any ideas on how this can be accomplished?

编辑:(这里是我目前的代码不起作用)

(here's my current code which doesn't work)

$(window).scroll(function () {
    if ($(this).scrollTop() < $(document).height() - 81) {
        $('#bottom_pic').css('bottom', "0px");
    }
    else {
        $('#bottom_pic').css('bottom', "81px");
    }
});

CSS:

#bottom_pic 
{
    position: fixed;
    bottom: 0px;
}

谢谢!

推荐答案

是一个很好的插件,可以实现这样的功能:

jQuery Waypoints is an excellent plugin to achieve things like this: Demo of fixed div after scrolling

这篇关于如何悬停固定元素,直到它到达某一点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 13:26