Advertisement
ArtSemkin

Untitled

Nov 11th, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* ======================================================================== */
  2.     /* 41. sliderHalfScreen */
  3.     /* ======================================================================== */
  4.     var SliderHalfScreen = function ($slider) {
  5.  
  6.         if (!$slider.length) {
  7.             return;
  8.         }
  9.  
  10.         var
  11.             $heading = $slider.find('h2, h1'),
  12.             $description = $slider.find('p'),
  13.             tl = new TimelineMax(),
  14.             $sliderImg = $slider.find('.js-slider-halfscreen__images'),
  15.             $sliderContent = $slider.find('.js-slider-halfscreen__content'),
  16.             overlapFactor = $sliderImg.data('overlap-factor') || 0;
  17.  
  18.         createSliders();
  19.         hoverLinks();
  20.  
  21.         function createSliders() {
  22.  
  23.             var sliderImg = new Swiper($sliderImg, {
  24.                 autoplay: {
  25.                     enabled: $sliderImg.data('autoplay-enabled') || false,
  26.                     delay: $sliderImg.data('autoplay-delay') || 6000,
  27.                     disableOnInteraction: true
  28.                 },
  29.                 direction: 'vertical',
  30.                 preloadImages: true,
  31.                 lazy: {
  32.                     loadPrevNext: true,
  33.                     loadOnTransitionStart: true
  34.                 },
  35.                 speed: $sliderImg.data('speed') || 1200,
  36.                 simulateTouch: false,
  37.                 watchSlidesProgress: true,
  38.                 pagination: {
  39.                     el: '.js-slider-headings__dots',
  40.                     type: 'bullets',
  41.                     bulletElement: 'div',
  42.                     clickable: true,
  43.                     bulletClass: 'slider__dot',
  44.                     bulletActiveClass: 'slider__dot_active'
  45.                 },
  46.                 on: {
  47.                     progress: function () {
  48.                         var swiper = this;
  49.                         for (var i = 0; i < swiper.slides.length; i++) {
  50.  
  51.                             var slideProgress = swiper.slides[i].progress,
  52.                                 innerOffset = swiper.width * overlapFactor,
  53.                                 innerTranslate = slideProgress * innerOffset;
  54.  
  55.                             try {
  56.                                 TweenMax.set(swiper.slides[i].querySelector('.slider-halfscreen__bg'), {
  57.                                     y: innerTranslate + 'px',
  58.                                     transition: swiper.params.speed + 'ms',
  59.                                     rotationZ: 0.01,
  60.                                     force3D: true
  61.                                 });
  62.                             } catch (error) {
  63.  
  64.                             }
  65.  
  66.                         }
  67.                     },
  68.                     touchStart: function () {
  69.                         var swiper = this;
  70.                         for (var i = 0; i < swiper.slides.length; i++) {
  71.                             try {
  72.                                 TweenMax.set(swiper.slides[i].querySelector('.slider-halfscreen__bg'), {
  73.                                     transition: '',
  74.                                     rotationZ: 0.01,
  75.                                     force3D: true
  76.                                 });
  77.                             } catch (error) {
  78.  
  79.                             }
  80.  
  81.                         }
  82.                     },
  83.                 }
  84.             });
  85.  
  86.             var sliderContent = new Swiper($sliderContent, {
  87.                 simulateTouch: false,
  88.                 effect: 'fade',
  89.                 fadeEffect: {
  90.                     crossFade: true
  91.                 },
  92.                 mousewheel: {
  93.                     eventsTarged: '.page-wrapper',
  94.                     releaseOnEdges: true,
  95.                 },
  96.                 navigation: {
  97.                     nextEl: '.js-slider-halfscreen__next',
  98.                     prevEl: '.js-slider-halfscreen__prev',
  99.                 },
  100.                 speed: $sliderImg.data('speed') || 1200,
  101.                 allowTouchMove: false,
  102.                 breakpoints: {
  103.                     992: {
  104.                         autoHeight: true
  105.                     }
  106.                 }
  107.             });
  108.  
  109.             sliderContent
  110.                 .on('slideNextTransitionStart', function () {
  111.  
  112.                     var
  113.                         $activeSlide = $(sliderContent.slides[sliderContent.activeIndex]),
  114.                         $activeHeading = $activeSlide.find($heading),
  115.                         $activeDescription = $activeSlide.find($description);
  116.  
  117.                     tl.clear();
  118.  
  119.                     $heading.each(function () {
  120.                         tl
  121.                             .add(hideWords($(this), 0.3, 0.02, '50px', true), '0')
  122.                             .add(hideWords($(this), '0', '0', '-50px'));
  123.                     });
  124.  
  125.                     $description.each(function () {
  126.                         tl.add(hideLines($(this), 0.6, 0.01, '100%', true), '0');
  127.                     });
  128.  
  129.                     tl
  130.                         .add(animateWords($activeHeading, 1.2, 0.02, true))
  131.                         .add(animateLines($activeDescription, 1.2, 0.01, true), '-=1.2');
  132.  
  133.                 })
  134.                 .on('slidePrevTransitionStart', function () {
  135.  
  136.                     var
  137.                         $activeSlide = $(sliderContent.slides[sliderContent.activeIndex]),
  138.                         $activeHeading = $activeSlide.find($heading),
  139.                         $activeDescription = $activeSlide.find($description);
  140.  
  141.                     tl.clear();
  142.  
  143.                     $heading.each(function () {
  144.                         tl
  145.                             .add(hideWords($(this), 0.3, 0.02, '-50px', false), '0')
  146.                             .add(hideWords($(this), '0', '0', '50px'));
  147.                     });
  148.  
  149.                     $description.each(function () {
  150.                         tl.add(hideLines($(this), 0.6, 0.01, '100%', true), '0');
  151.                     });
  152.  
  153.                     tl
  154.                         .add(animateWords($activeHeading, 1.2, 0.02, false))
  155.                         .add(animateLines($activeDescription, 1.2, 0.01), '-=1.2');
  156.  
  157.                 })
  158.                 .on('slideChange', function () {
  159.  
  160.                     var
  161.                         $activeSlide = $(sliderContent.slides[sliderContent.activeIndex]),
  162.                         $activeHeading = $activeSlide.find($heading),
  163.                         $activeDescription = $activeSlide.find($description);
  164.  
  165.                     tl.clear();
  166.  
  167.                     $heading.each(function () {
  168.                         tl
  169.                             .add(hideWords($(this), 0.3, 0.02, '-50px', false), '0')
  170.                             .add(hideWords($(this), '0', '0', '50px'));
  171.                     });
  172.  
  173.                     $description.each(function () {
  174.                         tl.add(hideLines($(this), 0.6, 0.01, '100%', true), '0');
  175.                     });
  176.  
  177.                     tl
  178.                         .add(animateWords($activeHeading, 1.2, 0.02, false))
  179.                         .add(animateLines($activeDescription, 1.2, 0.01), '-=1.2');
  180.  
  181.                 });
  182.  
  183.             sliderImg.controller.control = sliderContent;
  184.             sliderContent.controller.control = sliderImg;
  185.  
  186.         }
  187.  
  188.         function hoverLinks() {
  189.  
  190.             $document
  191.                 .on('mouseenter touchstart', '.slider-halfscreen__link', function () {
  192.  
  193.                     var $targetBackground = $sliderImg.find('.swiper-slide-active .slider-halfscreen__images-slide-inner'),
  194.                         $linkLine = $sliderContent.find('.swiper-slide-active .slider-halfscreen__link-line');
  195.  
  196.                     if (!$targetBackground.length) {
  197.                         return;
  198.                     }
  199.  
  200.                     TweenMax.to($targetBackground, 0.6, {
  201.                         scale: 1.05,
  202.                         ease: Expo.easeInOut
  203.                     });
  204.  
  205.                     TweenMax.to($linkLine, 0.6, {
  206.                         width: '70px',
  207.                         ease: Expo.easeInOut
  208.                     });
  209.  
  210.                 })
  211.                 .on('mouseleave touchend', '.slider-halfscreen__link', function () {
  212.  
  213.                     var $targetBackground = $sliderImg.find('.swiper-slide-active .slider-halfscreen__images-slide-inner'),
  214.                         $linkLine = $sliderContent.find('.swiper-slide-active .slider-halfscreen__link-line');
  215.  
  216.                     if (!$targetBackground.length) {
  217.                         return;
  218.                     }
  219.  
  220.                     TweenMax.to($targetBackground, 0.6, {
  221.                         scale: 1,
  222.                         ease: Expo.easeInOut
  223.                     });
  224.  
  225.                     TweenMax.to($linkLine, 0.6, {
  226.                         width: '60px',
  227.                         ease: Expo.easeInOut
  228.                     });
  229.  
  230.                 });
  231.  
  232.         }
  233.  
  234.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement