Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.81 KB | None | 0 0
  1. $(document).ready(function() {
  2.     // Has the animation played yet?
  3.     var animPlayed = false;
  4.    
  5.     $('div#mainContainer').scroll(function() {
  6.  
  7.         // Detecting if our element has scrolled into view.
  8.         function elementScrolled(elem) {
  9.             var docViewTop = $(window).scrollTop();
  10.             var docViewBottom = docViewTop + $(window).height();
  11.             var elemTop = $(elem).offset().top;
  12.             return ((elemTop <= docViewBottom) && (elemTop >= docViewTop));
  13.         }
  14.  
  15.         // Start the animation.
  16.         function playAnimation(){
  17.             lottie.loadAnimation(params);
  18.         }
  19.        
  20.         // If scrolled into view, call the animation function only once.
  21.         if(elementScrolled('.arrow--anim')) {
  22.             if(!animPlayed){
  23.                 var animPlayed = true;
  24.                 setTimeout(playAnimation, 500);
  25.             }
  26.         }
  27.     });
  28. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement