First, you'll want to start by tracking page scrolling. Secondly, you will want to animate the separation from left to right when necessary. To do this, you need to use the scroll function and several others for the animation part.
Here is the base for what you want, without scrolling.
function slider() { if (document.body.scrollTop > 100) //Show the slider after scrolling down 100px $('#slider').stop().animate({"margin-left": '0'}); else $('#slider').stop().animate({"margin-left": '-200'}); //200 matches the width of the slider }
Now you want to run this function while scrolling the user using:
$(window).scroll(function () { slider(); });
And finally, you also want to call the function when the user first arrives, if the user starts halfway down the page using:
$(document).ready(function () { slider(); });
A few words to note :
I hardcoded the width of the sliders to 200 pixels, and the starting point is 100 pixels. The stop() function is very important and stops the animation function from redundancy.
This is where jsfiddle works with related CSS
source share