使用GSAP滚动动画 [英] On scroll animation using GSAP

查看:119
本文介绍了使用GSAP滚动动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 GSAP 进行动画制作,当用户滚动时我需要滚动动画鼠标滚轮。现在动画正在加载页面。我需要内容应该在滚动上动画。前两篇文章正在发挥作用,但当我滚动它时,动画不起作用。

I am using GSAP for animation, I need on scroll animation when the user scrolls the mouse wheel. Now animation is working on page load. I need content should animate on the scroll. First two articles are working but when I scroll it than animation is not working.

(function() {
  var content = document.getElementById("content");
  var xScroll = 0;  // initialize
    function scrollHorizontally(e) {
        xScroll = xScroll+e.deltaY*20;
        // set limits to avoid overshooting and stucking at beginning or end
         var max = document.getElementById("content").innerWidth;
          if (xScroll <= 0) {
              xScroll = 0;
          } else if (xScroll >= max) {
              xScroll = max; //replace with the width of the scrollable container
          }
        // scroll smooth to xScroll
        TweenLite.to(content, 1, { ease: Power1.easeOut, scrollTo:{x:xScroll} });
        var rt = ($(window).width() - ($(".active_05").offset().left ));
        if(rt>200)
        {
          $(".about_menu").addClass("active");
        }
        else
        {
                    
        $(".about_menu").removeClass("active");
        }
        e.preventDefault();
    }
   if (content.addEventListener) {
        // Standard
        content.addEventListener("wheel", scrollHorizontally, false);
    } else {
        // IE 6/7/8
        content.attachEvent("onmousewheel", scrollHorizontally);
    }


      var article_1=document.getElementById("article_1");
    TweenLite.from(article_1, .5, { ease: Power0.easeOut, y: 10 });


    var article_2=document.getElementById("article_2");
    TweenLite.from(article_2, .5, { ease: Power0.easeOut, y: 10 });
     var article_3=document.getElementById("article_3");
    TweenLite.from(article_3, .5, { ease: Power0.easeOut, y: 15 });

      var article_3=document.getElementById("article_4");
    TweenLite.from(article_3, .5, { ease: Power0.easeOut, y: 15 });

      var article_3=document.getElementById("article_5");
    TweenLite.from(article_3, .5, { ease: Power0.easeOut, y: 15 });


})();

#content {
   position:fixed;
display: inline-block;
overflow-x: scroll;
width: 100%;
overflow-y: hidden;
top: 0;
right:0;
height: 100%;
}
#content #horizontal_scroll{
    overflow: hidden;
    width:400%;/*to increase the width */
}
#horizontal_scroll .full_screen_100
{
    height: 100%;
    background-color: #fff;
    display: flex;
}
#horizontal_scroll .full_screen_100 article{
    width: 900px;
    height: 100%;
    float:left;
    border-left: solid 1px #E2E2E2;

}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.2/plugins/CSSPlugin.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.3/plugins/ScrollToPlugin.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.2/TweenLite.min.js"></script>
<div id="content">
<div id="horizontal_scroll" id="scroll_container">
<div class="full_screen_100">
    <article>
    <p id="article_1">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
    consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
    proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </p>

</article>
<article>
    <p id="article_2">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo</p>
    <p id="article_3">consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
    proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</article>
<article>
    <p id="article_4">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
    tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo</p>
    <p id="article_5">consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
    cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
    proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</article>
</div>
</div>
</div>    

推荐答案

使用GSAP scrollmagic.Check这个例子 Gsap with scroll animation

use GSAP with scrollmagic.Check this examples Gsap with scroll animation

这篇关于使用GSAP滚动动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆