fixed div on bottom of page that stops in given place

前端 未结 3 1970
悲哀的现实
悲哀的现实 2020-12-06 19:02

I have fixed div on bottom of my page that works well. I wonder if there is some simple way to make it \"stop\" on some place in page when user srolls down to it. I want it

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-06 19:56

    I made this up for you: http://jsfiddle.net/XCYFG/1/.

    $(document).ready(function() {
        window._div1 = $('#div1'); //selector is expensive
        window._window = $(window);
        $(window).scroll(function(e) {
            _div1.css("top",
                      Math.min(_window.height(),
                               window.scrollY + 100)
                      + _window.height() - _div1.height() - 110);
        }).scroll();
    });
    

提交回复
热议问题