I want to move an image from the very left side of the screen as soon as it appears and while scrolling, it should move to the right side of the screen. I need to achieve this in pure JavaScript or CSS.
Exactly like this, https://jsfiddle.net/PvVdq/ except no JQuery.
$(document).ready(function () {
var $horizontal = $('#horizontal');
$(window).scroll(function () {
var s = $(this).scrollTop(),
d = $(document).height(),
c = $(this).height();
scrollPercent = (s / (d - c));
var position = (scrollPercent * ($(document).width() - $horizontal.width()));
$horizontal.css({
'left': position
});
});
});