我是GSAP的新手。
我在YouTube上关注MilklsNice的ScrollMagic和GSAP教程。
他是GSAP动画之一,他解释了如何制作一个动画,使 看起来像是从左到右打开一本书 。
var overlay_test = document.querySelector('.overlay_test');
var animate_in = new TimelineMax();
animate_in
.fromTo(overlay_test, 2,
{skewX: 10, scale: 1.5},
{skewX: 0, xPercent: 100, transformOrigin: "0% 100%", ease: Power2.easeOut})
.box_test{
position: relative;
overflow: hidden;
height: 350px;
}
.img_test{
width: 800px;
}
.overlay_test{
display: block;
position: absolute;
left: 0;
top: 0;
background:white;
width: 100%;
height: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.2/TweenMax.min.js"></script>
<div class="box_test">
<img class="img_test" src="https://images.unsplash.com/photo-1553696801-25638feb93fe?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1000&q=80" alt="korea">
<div class="overlay_test"></div>
</div>
(您也可以为此签出the CodePen)
在此webpage,我学习了如何从右向左显示div。代码如下:
var left = new TimelineMax ();
var rect = document.getElementById('rect');
left
.from(rect,2,{width:0},1)
.from(rect,2,{left:400},1)
Result
EDIT ON
body{
background: #414141;
overflow:hidden;
}
#rect{
position:relative;
width:400px;
height:350px;
margin: 20px;
background: green;
align-items: center;
overflow:hidden;
}
#copy{
position: absolute;
bottom: 0;
margin: 0 10px;
}
h1{
font-family: 'Work Sans', sans-serif;
color: white;
width: max-content;
margin: 0 auto;
font-size: 145px;
line-height: 100px;
}
.very{
font-size: 80px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.2/TweenMax.min.js"></script>
<div id="rect">
<div id="copy">
<h1 class="very">Very cool </h1>
<h1> Jack!</h1>
</div>
</div>
顺便说一句,
这个动画不是我想要的。因为,它只是将div从右向左移动 ,而不是像从右向左打开一本书一样 。但是,我仍然尝试:
var overlay_test = document.querySelectorAll('.overlay_test');
var animate_in = new TimelineMax();
animate_in
.from(overlay_test,2,{width:0},1)
.from(overlay_test,2,{left:800},1)
.box_test{
position: relative;
overflow: hidden;
height: 350px;
}
.img_test{
width: 800px;
}
.overlay_test{
display: block;
position: absolute;
left: 0;
top: 0;
background:white;
width: 100%;
height: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.2/TweenMax.min.js"></script>
<div class="box_test">
<img class="img_test" src="https://images.unsplash.com/photo-1553696801-25638feb93fe?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1000&q=80" alt="korea">
<div class="overlay_test"></div>
</div>
现在,图像消失了。因此,我认为我可以将动画应用于图片而不是覆盖图像。但是,现在动画是从屏幕的左上角开始的非常小的图像,并从那里开始扩展。
var img_test = document.querySelectorAll('.img_test');
var animate_in = new TimelineMax();
animate_in
.from(img_test,2,{width:0},1)
.from(img_test,2,{left:800},1)
.box_test{
position: relative;
overflow: hidden;
height: 350px;
}
.img_test{
width: 800px;
}
.overlay_test{
display: block;
position: absolute;
left: 0;
top: 0;
background:white;
width: 100%;
height: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.2/TweenMax.min.js"></script>
<div class="box_test">
<img class="img_test" src="https://images.unsplash.com/photo-1553696801-25638feb93fe?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1000&q=80" alt="korea">
</div>
这也不是我想要的。
我想制作一个动画,使 看起来像是从 有权离开 。 (与what I include at the beginning相反)。
我该如何实现? :)
答案 0 :(得分:1)
在动画right:0
至right:200%
中使用,以及在CSS中将left:0
更改为right:0
var overlay_test = document.querySelector('.overlay_test');
var animate_in = new TimelineMax();
animate_in
.fromTo(overlay_test, 2,
{skewX: 10, scale: 1.5 , right:0 },
{skewX: 0, right:"200%" ,transformOrigin: "0% 100%", ease: Power2.easeOut})
.box_test{
position: relative;
overflow: hidden;
height: 350px;
}
.img_test{
width: 800px;
}
.overlay_test{
display: block;
position: absolute;
right: 0;
top: 0;
background:white;
width: 100%;
height: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.2/TweenMax.min.js"></script>
<div class="box_test">
<img class="img_test" src="https://images.unsplash.com/photo-1553696801-25638feb93fe?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1000&q=80" alt="korea">
<div class="overlay_test"></div>
</div>