代码之家  ›  专栏  ›  技术社区  ›  Alex Rashkov

当我在某个点后滚动时,如何使div滚动?

  •  4
  • Alex Rashkov  · 技术社区  · 14 年前

    有什么想法吗?

    1 回复  |  直到 14 年前
        1
  •  1
  •   gblazex    14 年前

    [ Working demo ]

    var el  = $("#sticky");
    var win = $(window);
    var width  = el.width();
    var height = el.height();
    var win_height = $(window).height();
    
    window.onscroll = function() {
      var offset = el.offset().top + height - win_height;
      if ( win.scrollTop() > offset ) {
        window.onscroll = function() { 
          el.css({
            width: width,
            position: "absolute",
            top: win.scrollTop() + win_height - height
          });
        };  
      }
    };
    

    position: "fixed"
    bottom: 0