Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. .anim-area {
  2. visibility: hidden;
  3. opacity: 0;
  4. transition: all 1s;
  5.  
  6. &.anim-from-top { transform: translate3d(0, -12rem, 0); }
  7. &.anim-from-bottom { transform: translate3d(0, 12rem, 0); }
  8. &.anim-from-left { transform: translate3d(-20rem, 0, 0); }
  9. &.anim-from-right { transform: translate3d(20rem, 0, 0); }
  10.  
  11. @media (max-width: @screen-tablet) {
  12. &.anim-from-top { transform: translate3d(0, -6rem, 0); }
  13. &.anim-from-bottom { transform: translate3d(0, 6rem, 0); }
  14. &.anim-from-left { transform: translate3d(0, 6rem, 0); }
  15. &.anim-from-right { transform: translate3d(0, 6rem, 0); }
  16. }
  17.  
  18. &.anim-zoom { transform: scale(0); }
  19.  
  20. &.anim-area-loaded {
  21. visibility: visible;
  22. opacity: 1;
  23.  
  24. &.anim-from-top,
  25. &.anim-from-bottom,
  26. &.anim-from-left,
  27. &.anim-from-right { transform: translate3d(0, 0, 0); }
  28.  
  29. &.anim-zoom { transform: scale(1); }
  30. }
  31. }
  32.  
  33. const lazyLoad = function() {
  34. let wt = $(window).scrollTop(); // top of the window
  35. let wb = wt + $(window).height(); // bottom of the window
  36.  
  37. $('.anim-area').each(function() {
  38. let $el = $(this);
  39. let ot = $el.offset().top; // top of element
  40. let ob = ot + $el.height(); // bottom of element
  41.  
  42. if (!$el.attr('loaded') && wt <= ob && wb >= ot) {
  43. $el.addClass('anim-area-loaded').attr('loaded', true);
  44. }
  45. });
  46. };
  47.  
  48. $(document).ready(function() {
  49. lazyLoad();
  50. $(window).scroll(function() {
  51. lazyLoad();
  52. });
  53. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement