jquery - Parallax scrolling start at specific height -
i trying implement parallax scrolling website. works perfect. problem is, have parallax section @ bottom. when scrolling down, image have set background image further above, this:
the photo should stop @ begin of gray section, see bellow.
my code:
// can used $(document).ready() / $(window).load() $(document).ready(function() { // cache window object $window = $(window); $('section[data-type="background"]').each(function(){ var $bgobj = $(this); // assigning object $(window).scroll(function() { // scroll background @ var speed // ypos negative value because we're scrolling up! var ypos = -($window.scrolltop() / $bgobj.data('speed')); // put our final background position var coords = '50% '+ ypos + 'px'; // move background $bgobj.css({ backgroundposition: coords }); }); // window scroll ends }); });
below html markup:
<section class="quote" id="quote-home" data-speed="4" data-type="background"> <div class="container_12"> <header class="grid_12 centered"> <h1> beginning of knowlegde <br> discovery of <br> not understand.” </h1> <span class="cross-x"></span> <h2>- frank herbert</h2> </header><!-- end header.grid_12 --> <div class="clear"></div><!-- end div.clear --> </div><!-- end div.container_12 --> </section><!-- end section#quote --> <section id="twitter" class="alt">
and css:
#quote-home { height: 500px; margin: 0 auto; width: 100%; max-width: 100%; position: relative; background: url(../images/coffeescripthands.jpg) 50% 0 no-repeat; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; }
Comments
Post a Comment