Advertisement
ArtSemkin

Untitled

Jul 22nd, 2020
2,106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* ======================================================================== */
  2. /* 1. Animations */
  3. /* ======================================================================== */
  4. class Animations {
  5.   constructor() {
  6.     this._revealCurtain();
  7.     this._moveCurtain();
  8.     this._setCurtain();
  9.     this._animateChars();
  10.     this._animateLines();
  11.     this._animateWords();
  12.     this._hideChars();
  13.     this._hideLines();
  14.     this._hideWords();
  15.     this._animateHeadline();
  16.   }
  17.  
  18.   _setCurtain() {
  19.     gsap.registerEffect({
  20.       name: 'setCurtain',
  21.       effect: (target, config) => {
  22.         const
  23.           tl = new gsap.timeline(),
  24.           $target = $(target);
  25.  
  26.         if (!$target.length) {
  27.           return tl;
  28.         }
  29.  
  30.         const
  31.           $svg = $target.find('.curtain-svg'),
  32.           $normal = $target.find('.curtain-svg__normal'),
  33.           $curve = $target.find('.curtain-svg__curve'),
  34.           $rect = $target.find('.curtain__rect');
  35.  
  36.         tl
  37.           .set($target, {
  38.             display: 'none',
  39.             autoAlpha: 1,
  40.             y: config.y
  41.           })
  42.           .set($svg, {
  43.             fill: config.background,
  44.           });
  45.  
  46.         return tl;
  47.  
  48.       },
  49.       extendTimeline: true,
  50.       defaults: {
  51.         y: '100%'
  52.       }
  53.     });
  54.   }
  55.  
  56.   _moveCurtain() {
  57.     gsap.registerEffect({
  58.       name: 'moveCurtain',
  59.       effect: (target, config) => {
  60.         const
  61.           tl = new gsap.timeline(),
  62.           $target = $(target);
  63.  
  64.         if (!$target.length) {
  65.           return tl;
  66.         }
  67.  
  68.         const
  69.           $svg = $target.find('.curtain-svg'),
  70.           $normal = $svg.find('.curtain-svg__normal');
  71.  
  72.         let $curveTop, $curveBottom;
  73.  
  74.         if (window.innerWidth / window.innerHeight >= 1) {
  75.           $curveTop = $target.find('.curtain-svg__curve_top-desktop');
  76.           $curveBottom = $svg.find('.curtain-svg__curve_bottom-desktop');
  77.         } else {
  78.           $curveTop = $svg.find('.curtain-svg__curve_top-mobile');
  79.           $curveBottom = $svg.find('.curtain-svg__curve_bottom-mobile');
  80.         }
  81.  
  82.         tl
  83.           .set($target, {
  84.             display: 'block',
  85.             autoAlpha: 1
  86.           })
  87.           .set([$curveTop, $curveBottom], {
  88.             visibility: 'hidden',
  89.           })
  90.           .to($target, {
  91.             y: config.y,
  92.             duration: 1.8,
  93.             ease: 'expo.inOut'
  94.           });
  95.  
  96.         if (config.curve === 'top') {
  97.           tl
  98.             .set($normal, {
  99.               visibility: 'visible'
  100.             }, '0')
  101.             .to($normal, {
  102.               duration: 0.9,
  103.               ease: 'power2.out',
  104.               morphSVG: $curveTop[0]
  105.             }, '-=1.8')
  106.             .to($normal, {
  107.               duration: 0.9,
  108.               ease: 'power2.out',
  109.               morphSVG: $normal[0],
  110.               overwrite: 'all'
  111.             }, '-=0.9');
  112.         } else {
  113.           tl
  114.             .set($normal, {
  115.               visibility: 'visible',
  116.             }, '0')
  117.             .to($normal, {
  118.               duration: 0.9,
  119.               ease: 'power2.out',
  120.               morphSVG: $curveBottom[0],
  121.               overwrite: 'all',
  122.             }, '-=1.8')
  123.             .to($normal, {
  124.               duration: 0.9,
  125.               ease: 'power2.out',
  126.               morphSVG: $normal[0],
  127.             });
  128.         }
  129.  
  130.         tl.totalDuration(config.duration);
  131.  
  132.         return tl;
  133.  
  134.       },
  135.       extendTimeline: true,
  136.       defaults: {
  137.         duration: 2.4,
  138.         curve: 'top',
  139.         y: '0%'
  140.       }
  141.     });
  142.   }
  143.  
  144.   _revealCurtain() {
  145.     gsap.registerEffect({
  146.       name: 'revealCurtain',
  147.       effect: (target, config) => {
  148.         const
  149.           tl = new gsap.timeline(),
  150.           $target = $(target);
  151.  
  152.         if (!$target.length) {
  153.           return tl;
  154.         }
  155.  
  156.         const
  157.           $normal = $target.find('.curtain-svg__normal'),
  158.           $curve = $target.find('.curtain-svg__curve');
  159.  
  160.         tl
  161.           .set($target, {
  162.             y: '100%',
  163.             autoAlpha: 1
  164.           })
  165.           .set($normal, {
  166.             visibility: 'visible'
  167.           })
  168.           .set($curve, {
  169.             visibility: 'hidden',
  170.           })
  171.           .to($target, {
  172.             y: '0%',
  173.             duration: 1.8,
  174.             ease: 'expo.inOut'
  175.           })
  176.           .to($normal, {
  177.             duration: 0.9,
  178.             ease: 'power2.out',
  179.             morphSVG: $curve[0]
  180.           }, '-=1.8')
  181.           .to($normal, {
  182.             duration: 0.9,
  183.             ease: 'power2.out',
  184.             morphSVG: $normal[0],
  185.             overwrite: 'all'
  186.           }, '-=0.9');
  187.  
  188.         tl.totalDuration(config.duration)
  189.  
  190.         return tl;
  191.  
  192.       },
  193.       extendTimeline: true,
  194.       defaults: {
  195.         duration: 2.4
  196.       }
  197.     });
  198.   }
  199.  
  200.   _animateChars() {
  201.     gsap.registerEffect({
  202.       name: 'animateChars',
  203.       effect: (target, config) => {
  204.         const
  205.           $target = $(target),
  206.           $chars = $target.find('.split-text__char');
  207.  
  208.         let textAlign;
  209.  
  210.         if (!$chars.length) {
  211.           return;
  212.         }
  213.  
  214.         textAlign = $target.css('text-align');
  215.  
  216.         if (!config.stagger.from) {
  217.  
  218.           switch (textAlign) {
  219.             case 'left':
  220.               config.stagger.from = 'start';
  221.               break;
  222.             case 'center':
  223.               config.stagger.from = 'center';
  224.               break;
  225.             case 'right':
  226.               config.stagger.from = 'end';
  227.               break;
  228.           }
  229.  
  230.         }
  231.  
  232.         return gsap.to($chars, config);
  233.       },
  234.       defaults: {
  235.         xPercent: 0,
  236.         yPercent: 0,
  237.         x: '0%',
  238.         y: '0%',
  239.         autoAlpha: 1,
  240.         duration: 1,
  241.         ease: 'power3.inOut',
  242.         stagger: distributeByPosition({
  243.           from: 'start',
  244.           amount: 0.3
  245.         })
  246.       },
  247.       extendTimeline: true,
  248.     });
  249.   }
  250.  
  251.   _animateLines() {
  252.     gsap.registerEffect({
  253.       name: 'animateLines',
  254.       effect: (target, config) => {
  255.         const $target = $(target);
  256.         let $lines = $target.find('.split-text__line');
  257.  
  258.         if (!$lines.length) {
  259.           return;
  260.         }
  261.  
  262.         if (config.excludeEl) {
  263.           $lines = $lines.not(config.excludeEl);
  264.           delete config.excludeEl;
  265.         }
  266.  
  267.         return gsap.to($lines, config);
  268.       },
  269.       defaults: {
  270.         xPercent: 0,
  271.         yPercent: 0,
  272.         x: '0%',
  273.         y: '0%',
  274.         autoAlpha: 1,
  275.         duration: 1.2,
  276.         ease: 'power3.out',
  277.         stagger: {
  278.           amount: 0.08
  279.         }
  280.       },
  281.       extendTimeline: true,
  282.     });
  283.   }
  284.  
  285.   _animateWords() {
  286.     gsap.registerEffect({
  287.       name: 'animateWords',
  288.       effect: (target, config) => {
  289.         const
  290.           $target = $(target),
  291.           $words = $target.find('.split-text__word');
  292.  
  293.         if (!$words.length) {
  294.           return;
  295.         }
  296.  
  297.         return gsap.to($words, config);
  298.       },
  299.       defaults: {
  300.         duration: 1.2,
  301.         y: '0%',
  302.         ease: 'power3.out',
  303.         stagger: {
  304.           amount: 0.2
  305.         }
  306.       },
  307.       extendTimeline: true,
  308.     });
  309.   }
  310.  
  311.   _hideChars() {
  312.     gsap.registerEffect({
  313.       name: 'hideChars',
  314.       effect: (target, config) => {
  315.         const
  316.           $target = $(target),
  317.           $chars = $target.find('.split-text__char'),
  318.           textAlign = $target.css('text-align');
  319.  
  320.         if (!$chars.length) {
  321.           return;
  322.         }
  323.  
  324.         if (!config.stagger.from) {
  325.  
  326.           switch (textAlign) {
  327.             case 'left':
  328.               config.stagger.from = 'start';
  329.               break;
  330.             case 'center':
  331.               config.stagger.from = 'center';
  332.               break;
  333.             case 'right':
  334.               config.stagger.from = 'end';
  335.               break;
  336.           }
  337.  
  338.         }
  339.  
  340.         if (config.duration === 0) {
  341.           config.stagger = 0;
  342.         }
  343.  
  344.         return gsap.to($chars, config);
  345.       },
  346.       defaults: {
  347.         duration: 1.2,
  348.         x: '0%',
  349.         y: '100%',
  350.         autoAlpha: 0,
  351.         ease: 'power3.inOut',
  352.         stagger: distributeByPosition({
  353.           from: 'center',
  354.           amount: 0.3
  355.         })
  356.       },
  357.       extendTimeline: true,
  358.     });
  359.   }
  360.  
  361.   _hideLines() {
  362.     gsap.registerEffect({
  363.       name: 'hideLines',
  364.       effect: (target, config) => {
  365.         const
  366.           $target = $(target),
  367.           $lines = $target.find('.split-text__line');
  368.  
  369.         if (!$lines.length) {
  370.           return;
  371.         }
  372.  
  373.         if (config.duration === 0) {
  374.           config.stagger = 0;
  375.         }
  376.  
  377.         return gsap.to($lines, config);
  378.       },
  379.       defaults: {
  380.         y: '-100%',
  381.         autoAlpha: 1,
  382.         duration: 1.2,
  383.         ease: 'power3.out',
  384.         stagger: {
  385.           amount: 0.02
  386.         }
  387.       },
  388.       extendTimeline: true,
  389.     });
  390.   }
  391.  
  392.   _hideWords() {
  393.     gsap.registerEffect({
  394.       name: 'hideWords',
  395.       effect: (target, config) => {
  396.         const
  397.           $target = $(target),
  398.           $words = $target.find('.split-text__word');
  399.  
  400.         if (!$words.length) {
  401.           return;
  402.         }
  403.  
  404.         return gsap.to($words, config);
  405.       },
  406.       defaults: {
  407.         y: '-100%',
  408.         autoAlpha: 0,
  409.         duration: 1.2,
  410.         ease: 'power3.out',
  411.         stagger: {
  412.           amount: 0.02
  413.         }
  414.       },
  415.       extendTimeline: true,
  416.     });
  417.   }
  418.  
  419.   _animateHeadline() {
  420.     gsap.registerEffect({
  421.       name: 'animateHeadline',
  422.       effect: (target, config) => {
  423.         const
  424.           $target = $(target);
  425.  
  426.         let textAlign;
  427.         textAlign = $target.css('text-align');
  428.  
  429.         if (!config.transformOrigin) {
  430.  
  431.           switch (textAlign) {
  432.             case 'left':
  433.               config.transformOrigin = 'left center';
  434.               break;
  435.             case 'center':
  436.               config.transformOrigin = 'center center';
  437.               break;
  438.             case 'right':
  439.               config.transformOrigin = 'right center';
  440.               break;
  441.           }
  442.  
  443.         }
  444.  
  445.         return gsap.to($target, config);
  446.       },
  447.       defaults: {
  448.         scaleX: 1,
  449.         scaleY: 1,
  450.         duration: 1.2,
  451.         ease: 'power3.inOut',
  452.       },
  453.       extendTimeline: true,
  454.     });
  455.   }
  456. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement