Advertisement
artemsemkin

Untitled

Nov 13th, 2023 (edited)
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function PJAXAnimateClonedImage(data, duration = 2.0) {
  2.   window.dispatchEvent(new CustomEvent('arts/barba/transition/clone/before'));
  3.  
  4.   return new Promise((resolve, reject) => {
  5.     const
  6.       tl = new gsap.timeline(),
  7.       $nextContainer = $(data.next.container),
  8.       $curtain = $('#js-page-transition-curtain'),
  9.       $nextMasthead = $nextContainer.find('.section-masthead'),
  10.       background = $nextMasthead.attr('data-background-color'),
  11.       $target = $nextMasthead.find('.js-transition-img'),
  12.       target = $target.get(0),
  13.       $clone = $('.clone'),
  14.       $bgClone = $clone.find('.js-transition-img__transformed-el'),
  15.       $bgTarget = $target.find('.js-transition-img__transformed-el'),
  16.       bgTarget = $bgTarget.get(0);
  17.  
  18.     if (!$target.length || !$clone.length) {
  19.       reject(false);
  20.       return;
  21.     }
  22.  
  23.     const bgTargetProperties = $bgTarget.css(['width', 'height', 'objectPosition', 'objectFit']),
  24.       {
  25.         top,
  26.         left,
  27.         width,
  28.         height,
  29.       } = target.getBoundingClientRect(),
  30.       bgTargetScale = gsap.getProperty(bgTarget, 'scale'),
  31.       bgTargetTranslateX = gsap.getProperty(bgTarget, 'x'),
  32.       bgTargetTranslateY = gsap.getProperty(bgTarget, 'y'),
  33.       targetTransform = $target.css('transform'),
  34.       targetBorderRadius = $target.css('border-radius'),
  35.       targetClippath = $clone.css('clip-path') === 'none' ? '' : 'circle(100% at center)';
  36.  
  37.  
  38.     tl
  39.       .setCurtain($curtain, {
  40.         background
  41.       })
  42.       .set($clone, {
  43.         maxWidth: '100%',
  44.         maxHeight: '100%',
  45.       })
  46.       .add([
  47.         gsap.to($bgClone, {
  48.           scale: bgTargetScale,
  49.           xPercent: bgTargetTranslateX,
  50.           yPercent: bgTargetTranslateY,
  51.           paddingBottom: 0,
  52.           width: bgTargetProperties.width,
  53.           height: bgTargetProperties.height,
  54.           objectFit: bgTargetProperties.objectFit,
  55.           objectPosition: bgTargetProperties.objectPosition,
  56.           duration: 1.2,
  57.           ease: 'expo.inOut',
  58.           transition: 'none',
  59.           top: 'auto',
  60.           left: 'auto',
  61.           right: 'auto',
  62.           bottom: 'auto',
  63.           autoRound: false
  64.         }),
  65.         gsap.to($clone, {
  66.           transform: targetTransform,
  67.           top,
  68.           left,
  69.           width,
  70.           height,
  71.           duration: 1.2,
  72.           ease: 'expo.inOut',
  73.           transition: 'none',
  74.           borderRadius: targetBorderRadius,
  75.           clipPath: targetClippath,
  76.           autoRound: false,
  77.           onComplete: () => {
  78.             Scroll.scrollToTop();
  79.           }
  80.         }),
  81.         gsap.effects.moveCurtain($curtain, {
  82.           y: '0%',
  83.           duration: 1.2
  84.         }),
  85.       ])
  86.       .to($nextContainer, {
  87.         duration: 0.2,
  88.         clearProps: 'all',
  89.         autoAlpha: 1,
  90.       }, '-=0.3')
  91.       .setCurtain($curtain)
  92.       .add(() => {
  93.         resolve(true);
  94.       })
  95.       .totalDuration(duration);
  96.   });
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement