简体   繁体   English

SVG-动画的Greensock时间轴

[英]SVG - Greensock Timeline for animation

What is the GSAP counterpart of the additive and accumulate animation attributes in SVG ? SVG中 additiveaccumulate动画属性的GSAP对应项是什么? I am animating using click events so I want to continue animation from the last state of the object. 我正在使用单击事件制作动画,因此我想从对象的最后状态继续进行动画处理。 Or is there a way to access those attributes. 还是有一种方法可以访问这些属性。

I am just starting out, so any links to guides or tutorials is appreciated. 我才刚刚起步,因此赞赏所有指向指南或教程的链接。

 var svgNS = "http://www.w3.org/2000/svg"; function anim(evt) { if (window.svgDocument == null) svgDoc = evt.target.ownerDocument; rot('shape', 120); } function rot(target_id, angle) { var my_element = svgDoc.getElementById(target_id); var a = svgDoc.createElementNS(svgNS, "animateTransform"); var bb = my_element.getBBox(); var cx = bb.x + bb.width / 2; var cy = bb.y + bb.height / 2; a.setAttributeNS(null, "attributeName", "transform"); a.setAttributeNS(null, "attributeType", "XML"); a.setAttributeNS(null, "type", "rotate"); a.setAttributeNS(null, "dur", "1s"); a.setAttributeNS(null, "repeatCount", "1"); a.setAttributeNS(null, "fill", "freeze"); a.setAttributeNS(null, "additive", "sum"); a.setAttributeNS(null, "accumulate", "sum"); a.setAttributeNS(null, "from", "0 " + cx + " " + cy); a.setAttributeNS(null, "to", angle + " " + cx + " " + cy); my_element.appendChild(a); a.beginElement(); } 
 <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="500px" height="500px" viewBox="0 0 500 500" enable-background="new 0 0 500 500" xml:space="preserve"> <g id="shape"> <circle fill="#FFA557" stroke="#000000" stroke-miterlimit="10" cx="254.186" cy="247.288" r="107.203" /> <polygon fill="#8CFFD5" stroke="#000000" stroke-miterlimit="10" points="239.634,218.5 225.083,193.5 239.634,168.5 268.736,168.5 283.288,193.5 268.736,218.5 " /> <polygon fill="#8CFFD5" stroke="#000000" stroke-miterlimit="10" points="239.634,268.5 225.083,243.5 239.634,218.5 268.736,218.5 283.288,243.5 268.736,268.5 " /> <polygon fill="#8CFFD5" stroke="#000000" stroke-miterlimit="10" points="195.634,243.5 181.083,218.5 195.634,193.5 224.737,193.5 239.288,218.5 224.737,243.5 " /> <polygon fill="#8CFFD5" stroke="#000000" stroke-miterlimit="10" points="282.635,243.5 268.083,218.5 282.635,193.5 311.736,193.5 326.288,218.5 311.736,243.5 " /> </g> <g onclick="anim(evt)"> <rect x="123.5" y="391.5" fill="#6E005D" stroke="#000000" stroke-miterlimit="10" width="268" height="77" /> <text transform="matrix(1 0 0 1 184.0811 439.5081)" fill="#FFFFFF" font-family="'ComicSansMS'" font-size="36">Click Me</text> </g> </svg> 

I am not sure if I understand your question correctly but is this the kind of effect you are trying to reproduce using TweenMax ? 我不知道如果我正确地理解你的问题,但这个你正在尝试使用重现样的效果TweenMax Let me know. 让我知道。

Update #1: 更新#1:

Using TimelineMax : 使用TimelineMax

  • Keep adding new TweenMax tweens into an existing timeline instance by using the add() method of TimelineMax . 继续使用TimelineMaxadd()方法将新的TweenMax补间添加到现有的timeline实例中。
  • Check to see if timeline is currently in a playing state, if not, play() it. 检查timeline当前是否处于播放状态,如果不是,则对其进行play()

jsFiddle #1 . jsFiddle#1

Update #2: 更新#2:

  • Increment the speed of timeline using timeScale() on a per-click basis. 在每次点击的基础上使用timeScale()增加timeline的速度。
  • Set a cap on this timeScale() property. 为此timeScale()属性设置一个上限。
  • Add an onComplete callback to the timeline instance to clear() the timeline . onComplete回调添加到timeline实例以clear() timeline

jsFiddle #2 . jsFiddle#2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM