html - background image that moves when you scroll down the page -
i keep seeing websites background image subtly moves when scroll down. nice effect i'm not sure how this? i'm experienced html, css , jquery haven't done before!
i have simple jsfiddle below need please!
many thanks,
code snippet - more available using jsfiddle link
.background { background-image: url(example.pjg); background-repeat: no-repeat; height: 600px; width: 100%; }
like tylerh said, it's called parallax. can see example here.
using javascript:
var velocity = 0.5; function update(){ var pos = $(window).scrolltop(); $('.container').each(function() { var $element = $(this); // subtract height b/c of padding var height = $element.height()-18; $(this).css('backgroundposition', '50% ' + math.round((height - pos) * velocity) + 'px'); }); }; $(window).bind('scroll', update);
Comments
Post a Comment