To begin, you should start monitoring the page scroll. Next, consider animating the division from left to right as needed. This will involve using the scroll
function along with other animation functions.
Below is a basic structure without the scroll functionality included:
function slider() {
if (document.body.scrollTop > 100) //Display the slider after scrolling down 100px
$('#slider').stop().animate({"margin-left": '0'});
else
$('#slider').stop().animate({"margin-left": '-200'}); //200 is the width of the slider
}
You can then trigger this function while the user scrolls by using:
$(window).scroll(function () {
slider();
});
Lastly, ensure to call the function when the user first arrives on the page in case they have scrolled halfway down already:
$(document).ready(function () {
slider();
});
A couple of points to keep in mind:
I've set the slider's width to 200px and the starting point to 100px in the code.
The stop()
function is crucial as it prevents redundant calls to the animate function.
For a live demonstration, check out this jsfiddle along with the corresponding CSS.