首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用脚本控制animateMotion

使用脚本控制animateMotion
EN

Stack Overflow用户
提问于 2013-04-26 04:56:38
回答 4查看 346关注 0票数 3

我已经用SVG创建了一条路径,并且我正在制作一个球来沿着它移动。

但是有没有什么办法可以控制球的移动呢?

例如,球开始停止,当我按键盘上的右箭头时,球沿顺时针方向移动,当我按左箭头时,球逆时针移动……

有可能吗?

下面是svg代码:

代码语言:javascript
运行
复制
<svg width="800" height="800" viewBox="0 0 800 800" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink">

<!-- Draw the outline of the motion path in grey, along
     with 2 small circles at key points -->
<path d="M66,89.32c18,143,154,82,97,118s-187,38-152,102s114,105,163,74
s89-111,89-127s18-128,13-155s-29-67-57-80s-47-14-62-17s-17-8-32,0s-40,23-47,30s-11,20-16,24s-14,29-14,29L66,89.32z" stroke="lightgrey" stroke-width="2" fill="none" id="theMotionPath"/>

<!-- Here is a red circle which will be moved along the motion path. -->
<circle cx="" cy="" r="5" fill="red">

    <!-- Define the motion path animation -->
    <animateMotion dur="6s" repeatCount="indefinite">
       <mpath xlink:href="#theMotionPath"/>
    </animateMotion>
</circle>

我把代码放在这里:http://jsfiddle.net/fPQv2/

谢谢!!

EN

Stack Overflow用户

回答已采纳

发布于 2013-04-26 23:53:08

我能做的最好的事情,就是我添加了这个脚本,这样我就可以暂停和取消暂停动画……但仍然不是我想要的.

代码语言:javascript
运行
复制
var pause = document.getElementById('draw');
var unPause = document.getElementById('draw');

function parar(){
    pause.pauseAnimations();
}
function voltar(){
    unPause.unpauseAnimations();
}

    $(window).keydown(function (e) {
        if (e.keyCode == 39) {
            setTimeout(voltar,10);
            setTimeout(parar,500);
        }
    }); 
票数 1
EN
查看全部 4 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16224556

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档