GreenSock 动画没有按预期工作
GreenSock animation not working as expected
我正在尝试按以下顺序使用介绍文本和箭头制作介绍页面动画:
背景图片来回移动了两次。之后,箭头应从 1 缩放到 1.5,并再次缩放到原始大小
介绍文本也应缩放到 1.5 并重新缩放到其原始大小
由于某些原因,箭头和文本从一开始就缩放到 1.5,如何在背景图像动画仍然是 运行 的情况下保持箭头和文本的大小?
这是目前的代码:
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes">
<meta charset="utf-8">
<style type="text/css">
.intro-text {
display: block;
font-size: 16px !important;
text-transform: uppercase;
font-weight: bold;
position: fixed;
top: 50%;
right: 140px;
z-index: 99;
color: red;
}
.intro-arrow {
display: block;
font-size: 16px !important;
text-transform: uppercase;
font-weight: bold;
position: fixed;
top: 45%;
right: 70px;
z-index: 99;
color: white;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.1.1/gsap.min.js" crossorigin="anonymous"></script>
<script>
var tl = new TimelineMax();
tl
.fromTo("body", 0.5, {x:-15}, {x:0})
.fromTo("body", 0.5, {x:-15}, {x:0})
.fromTo('.intro-arrow', 0.5, {scale: 1},{scale: 1.5})
.fromTo('.intro-arrow', 0.5, {scale: 1.5},{scale: 1})
.fromTo('.intro-text', 0.5, {scale: 1}, {scale: 1.5})
.fromTo('.intro-text', 0.5, {scale: 1.5}, {scale: 1})
</script>
</head>
<body>
<div class="container" style="height:100vh; background-image: url('http://rheinmainsport.de/images/news/boxcamp.png')">
<div class="intro-text">Here some intro text</div>
<div class="intro-arrow">
<span class="SVGInline"><!--?xml version="1.0" encoding="UTF-8"?-->
<svg class="SVGInline-svg" width="59px" height="130px" viewBox="0 0 59 130" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 63.1 (92452) - https://sketch.com -->
<title>Fill-1</title>
<desc>Created with Sketch.</desc>
<g id="Main-Story" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="Arrow" transform="translate(-166.000000, 0.000000)" fill="#ff0000" fill-rule="nonzero">
<g id="icon/arrow/x-large/white" transform="translate(166.000000, 0.000000)">
<path d="M2.2131,130.025 L0.0001,128 L54.7241,68.21 C56.3381,66.446 56.3381,63.578 54.7241,61.815 L0.0001,2.025 L2.2131,0 L56.9371,59.789 C59.5731,62.669 59.5731,67.355 56.9371,70.235 L2.2131,130.025 Z" id="Fill-1"></path>
</g>
</g>
</g>
</svg>
</span>
</div>
</div>
</body>
</html>
在 CodePen 上
这是因为您正在使用 .fromTo()
制作动画。 .from()
和 .fromTo()
s 默认情况下将 immediateRender
设置为 true
(因为通常这是人们想要的)。对于导致缩放问题的补间动画,您可以将 immediateRender
设置为 false
。
或者,只需使用 .to() 调用即可。使用 repeat
和 yoyo
也可以使您的工作更轻松。我如何以 GSAP 3 格式编写它:
var tl = gsap.timeline();
tl
.fromTo("body", {x: -15}, {x: 0, repeat: 1})
.to('.intro-arrow', {scale: 1.5, repeat: 1, yoyo: true})
.to('.intro-text', {scale: 1.5, repeat: 1, yoyo: true})
持续时间可以省略,因为 0.5 是 GSAP 3 中的默认值。如果您想更改补间的持续时间,我们建议您将其放在 vars 参数中,例如 duration: 1
。
我们强烈推荐 Getting Started 文章,因为您可以学到很多与此类似的东西:)
我们还强烈推荐 the GreenSock forums,因为您将能够从 GSAP 和网络动画专家那里获得快速、高质量的帮助。
我正在尝试按以下顺序使用介绍文本和箭头制作介绍页面动画:
背景图片来回移动了两次。之后,箭头应从 1 缩放到 1.5,并再次缩放到原始大小
介绍文本也应缩放到 1.5 并重新缩放到其原始大小
由于某些原因,箭头和文本从一开始就缩放到 1.5,如何在背景图像动画仍然是 运行 的情况下保持箭头和文本的大小?
这是目前的代码:
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes">
<meta charset="utf-8">
<style type="text/css">
.intro-text {
display: block;
font-size: 16px !important;
text-transform: uppercase;
font-weight: bold;
position: fixed;
top: 50%;
right: 140px;
z-index: 99;
color: red;
}
.intro-arrow {
display: block;
font-size: 16px !important;
text-transform: uppercase;
font-weight: bold;
position: fixed;
top: 45%;
right: 70px;
z-index: 99;
color: white;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.1.1/gsap.min.js" crossorigin="anonymous"></script>
<script>
var tl = new TimelineMax();
tl
.fromTo("body", 0.5, {x:-15}, {x:0})
.fromTo("body", 0.5, {x:-15}, {x:0})
.fromTo('.intro-arrow', 0.5, {scale: 1},{scale: 1.5})
.fromTo('.intro-arrow', 0.5, {scale: 1.5},{scale: 1})
.fromTo('.intro-text', 0.5, {scale: 1}, {scale: 1.5})
.fromTo('.intro-text', 0.5, {scale: 1.5}, {scale: 1})
</script>
</head>
<body>
<div class="container" style="height:100vh; background-image: url('http://rheinmainsport.de/images/news/boxcamp.png')">
<div class="intro-text">Here some intro text</div>
<div class="intro-arrow">
<span class="SVGInline"><!--?xml version="1.0" encoding="UTF-8"?-->
<svg class="SVGInline-svg" width="59px" height="130px" viewBox="0 0 59 130" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 63.1 (92452) - https://sketch.com -->
<title>Fill-1</title>
<desc>Created with Sketch.</desc>
<g id="Main-Story" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="Arrow" transform="translate(-166.000000, 0.000000)" fill="#ff0000" fill-rule="nonzero">
<g id="icon/arrow/x-large/white" transform="translate(166.000000, 0.000000)">
<path d="M2.2131,130.025 L0.0001,128 L54.7241,68.21 C56.3381,66.446 56.3381,63.578 54.7241,61.815 L0.0001,2.025 L2.2131,0 L56.9371,59.789 C59.5731,62.669 59.5731,67.355 56.9371,70.235 L2.2131,130.025 Z" id="Fill-1"></path>
</g>
</g>
</g>
</svg>
</span>
</div>
</div>
</body>
</html>
在 CodePen 上
这是因为您正在使用 .fromTo()
制作动画。 .from()
和 .fromTo()
s 默认情况下将 immediateRender
设置为 true
(因为通常这是人们想要的)。对于导致缩放问题的补间动画,您可以将 immediateRender
设置为 false
。
或者,只需使用 .to() 调用即可。使用 repeat
和 yoyo
也可以使您的工作更轻松。我如何以 GSAP 3 格式编写它:
var tl = gsap.timeline();
tl
.fromTo("body", {x: -15}, {x: 0, repeat: 1})
.to('.intro-arrow', {scale: 1.5, repeat: 1, yoyo: true})
.to('.intro-text', {scale: 1.5, repeat: 1, yoyo: true})
持续时间可以省略,因为 0.5 是 GSAP 3 中的默认值。如果您想更改补间的持续时间,我们建议您将其放在 vars 参数中,例如 duration: 1
。
我们强烈推荐 Getting Started 文章,因为您可以学到很多与此类似的东西:)
我们还强烈推荐 the GreenSock forums,因为您将能够从 GSAP 和网络动画专家那里获得快速、高质量的帮助。