jQuery or CSS Animate - HTML Element moves down on scroll -
i'm trying set timeline, marker moves user scrolls down. i've set code follows:
html
<div class="boxone"></div> <div class="boxtwo"><div class="animatedcircle"></div></div> css
.boxone { width: 400px; height: 4000px; background: red; float: left; } .boxtwo { width: 400px; height: 4000px; background: blue; border-left: 1px solid black; float: left; } .animatedcircle { border: 1px solid black; width: 25px; height: 25px; border-radius: 40px; position: absolute; right: 403px; top: 50px; } jquery
$(document).ready(function () { var el = $('.animatedcircle'); var originalelpos = el.offset().top; // take on page //run on scroll $(window).scroll(function () { var el = $('.animatedcircle'); // important! (local) var elpos = el.offset().top; // take current situation var windowpos = $(window).scrolltop(); var finaldestination = windowpos + originalelpos; el.stop().animate({ 'top': finaldestination }, 400); }); }); http://codepen.io/elainem/pen/tiyhb
how go animating marker move down when scroll down?
you mean circle? if yes, change .animatedcircle position fixed.
Comments
Post a Comment