javascript - animate left not working on page scroll -
i have 2 div's in pink , sky blue color, make them same height , width. pink div covering height of screen, when scroll down , scrollbar reaches sky blue want animate blue div right , when scrollbar leave div want div move comes from.
$(document).ready(function(){  $(window).scrolltop(function(){  $(this).scroll(function(){  var scrolltoporbottom = $(document).height() - $(window).height() - $(window).scrolltop();    if(flag === 0 && scrolltoporbottom < 1256){     $('#bluediv').animate({right: '200px'}, function(){         flag = 1;     });  }  if(flag === 1 && scrolltoporbottom < 740){     console.log(scrolltoporbottom);  $('#bluediv').slideleft();     flag = 0;    }           });   });     }); 
you can apply logic:
- use - transitionanimate element, css this:- #bluediv { width: 50%; height: 100px; background-color: blue; position: absolute; left:0; transition:left 2s linear; } #bluediv.right { left:50% }
- with jquery check how far element sky top , trigger event if scroll reach that: - $(window).scroll(function() { var offt = $('#two').offset().top - $(window).height(), scrt = $(window).scrolltop(); if(scrt >= offt) { $('#bluediv').addclass('right') } else { $('#bluediv').removeclass('right') } });
Comments
Post a Comment