html - CSS, box that scrolls but doesn't disappear -
i not sure if wording right. have googled different terms. in plain english want a:
box scrolls doesn't disappear.
i trying achieve boxes similar linkedin's side boxes. scroll page stop scrolling , never disappear.
a mix of: position:fixed
, position:absolute
?
i have other boxes on box question, positioned in exact same area side box.
it's not possible raw css, though is possible if use javascript. need work out how far down page user is, , add content every time scroll number of pixels.
this can achieved jquery. can bind $(window).scroll()
function, , check height $(window).scrolltop()
. append new content .append()
.
in following example, $(window).scrolltop() + $(window).height() > $(document).height() - 100
checks when user 100 pixels away reaching end of content. new content appended, , scrollbar grows in length.
because checks against height of document, every time end of new content reached, loop trigger again, , more content created. thus, following provides infinite scroll:
/* initial content */ (var = 0; < 100; i++) { $("#scroll").append($("<div class='original-content'>original content</div>")); } /* bonus content */ $(window).scroll(function(event) { var scroll = $(window).scrolltop(); if($(window).scrolltop() + $(window).height() > $(document).height() - 100) { (var = 0; < 100; i++) { $("#scroll").append($("<div class='new-content'>new content</div>")); } } });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="scroll"></div>
hope helps! :)
Comments
Post a Comment