javascript - Increment variable as .offsetTop() increments -


so writing custom parallaxing thing website working on.

it's simple:

$('.bl-content').scroll(function(){     $('.prlx-image img').each(function(){         if($(this).parents('div.prlx-image').offset().top < $('.page-type--sfs .bl-content').height()){             $(this).css('bottom', $('.page-type--sfs .bl-content').scrolltop() * -.3);         }     }); }); 

it checks see if image on page , starts pulling image faster slower page scrolls. problem here value image being pulled same each image. works fine images on page when loads further down has "parallaxed" out of container time gets view.

the images absolutely positioned within container div.

i need start scrolltop 0 when image gets scrolled view...

update:

i have been playing around , think on something:

var offset = []  $('.prlx-image').each(function(i){     offset[i] = $(this).offset().top; });  $('.bl-content').scroll(function(){     $('.prlx-image img').each(function(i){         if($(this).parents('div.prlx-image').offset().top < $('.page-type--sfs .bl-content').outerheight()){             $(this).css('bottom', ($('.page-type--sfs .bl-content').scrolltop() * -.3) - offset[i]);         }     }); }); 

so if subtract value of value of scrolltop() theoretically should work....but reason not working :(

if helps html each image contained in looks this:

<div class="prlx-image">     <img src="/assets/uploads/menncars.jpg" class="img-responsive"> </div> 

and css:

prlx-image{     height: 350px;     margin: 30px 0;     overflow: hidden;     position: relative; }  .prlx-image img{     position: absolute;     left: 0;     right: 0;     bottom: 0;     width: 100%; } 


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -