I have been making a project and i have seen some modern websites showing <div>
or <ul>
after certain amount of pixels are scrolled, instead of seperating them into different index pages.
For that, i have been able to do the first step, wrap every 16 elements into different <ul>
, but i couldn't figure out how to hide other <ul>
element before <ul>
is fully scrolled and then show up other <ul>
and continue doing so until final <ul>
element (final page) is reached by scrolling.
HTML:
<div class="product_container">
<ul class="products" style="list-style-type:none">
<li><div class="product"></div></li>
<li><div class="product"></div></li>
<li><div class="product"></div></li>
<li><div class="product"></div></li>
<li><div class="product"></div></li>
<li><div class="product"></div></li>
<li><div class="product"></div></li>
<li><div class="product"></div></li>
<li><div class="product"></div></li>
<li><div class="product"></div></li>
<li><div class="product"></div></li>
<li><div class="product"></div></li>
<li><div class="product"></div></li>
<li><div class="product"></div></li>
<li><div class="product"></div></li>
<li><div class="product"></div></li>
<li><div class="product"></div></li>
<li><div class="product"></div></li>
<li><div class="product"></div></li>
<li><div class="product"></div></li>
<li><div class="product"></div></li>
</ul>
</div>
CSS:
.product_container {
position: relative;
top: 420px;
height: 1000px;
}
.products {
display: flex;
display: -ms-flex;
flex-direction: row;
-ms-flex-direction: row;
flex-wrap: wrap;
-ms-flex-wrap: wrap;
justify-content: center;
-ms-justify-content: center;
align-items: center;
-ms-align-items: center;
}
.products li {
display: inline-block;
margin-left: 3%;
margin-bottom: 3%;
}
.product {
background-color: black;
border: solid 2px white;
border-radius: 5px;
height: 18%;
width: 15%;
min-height: 310px;
min-width: 250px;
}
And Javascript i used to wrap up all 16 elements in every <ul>
(pages):
$(document).ready(function() {
var lis = $(".products li");
for(var i = 0; i < lis.length; i+=16) {
lis.slice(i, i+16)
.wrapAll("<div class='products'></div>");
}
});
Is it possible to do something relevant to this? I have been researching for long and i have only found out how to show div when only specific amount of height is scrolled, for example: 400px, but how could is there any solution so it display's other ul after every ul is scrolled.
For example:
There are 10 ul
elements with 16 li
elements inside all of them: ul1, ul2, ul3, ul4, ul5, ul6, ul7, ul8, ul9, ul10.
When user scrolls down to at the end of ul1, ul2 will be displayed, when user scrolls down to at the end of ul2, ul3 will be displayed, and etc.
In short, it's called "Lazy Loading" or "Infinite Scrolling" as well.
What's the best strategy for doing this? Thanks!