111

111


if (module.hot) {
  module.hot.accept();
}
export default function (element) {

  //** Hero paralax animation
  let heroParalax = function () {
    let $hero = $('.hero--faq');
    if (!$hero.length) return;

    let
      $heroImg = $('.hero__image'),
      $heroTitle = $('.hero__title-wrapper'),
      $heroImg$heroTitle = $('.hero__title-wrapper, .hero__image'),
      scale = 1,
      opacity = 1,
      translate = 0,
      diffScale = 0.2,
      diffOpacity = 1,
      diffTranslate,
      $window = $(window),
      scrollTop,
      heroScale,
      heroOpacity,
      heroHeight = $hero.height(),
      heroTranslate;

    function run() {
      scrollTop = $window.scrollTop();
      diffTranslate = heroHeight / 2;
      heroScale = scale + ((scrollTop / heroHeight) * diffScale);
      heroOpacity = opacity - ((scrollTop / heroHeight) * diffOpacity);
      heroTranslate = translate + ((scrollTop / heroHeight) * diffTranslate);
      if (scrollTop <= heroHeight) {
        $heroImg.css({
          'transform': 'scale(' + heroScale + ')',
        });
        $heroTitle.css({
          'transform': 'translateY(' + heroTranslate + 'px)',
        });
        $heroImg$heroTitle.css({
          'opacity': heroOpacity,
        });
      }
    }

    $(window).scroll(run);
  };
  heroParalax();


  //** Changing link color and scroll
  let linksColor = function () {
    let
      $window = $(window),
      scrollTop,
      $sidebar = $(element),
      $links = $sidebar.find('a[href*=\\#]'),
      links_qt = $links.length,
      $ids = $links.map((i, el) => $(el).attr('href')),
      $els = $ids.map((i, id) => $(id));

    console.log($els[0].length);
    console.log($els[0]);
    console.log($els[1].length);
    console.log($els[1]);
    console.log($els[2].length);
    console.log($els[2]);
    console.log($els[3].length);
    console.log($els[3]);



    function run() {
      scrollTop = $window.scrollTop();

      for (let i = 0; i <= links_qt - 1; ++i) {
        let $link = $links.eq(i);
        let $linkTarget = $els[i];
        
        if($linkTarget.length){
          let navTop = $linkTarget.offset().top - 1;
          
          if (scrollTop >= navTop) {
            $links.removeClass("active");
            $link.addClass("active");
          }
          
          $link.on('click', function (event) {
            event.preventDefault();
              $('html,body').animate({
                scrollTop: $(this.hash).offset().top
              }, 500);
              //enable disable hash in address bar
              // window.location.hash=this.hash;
          });
        }
        
      }
    }

    $(window).scroll(run);
  };
  linksColor();
}


Report Page