简体   繁体   English

箭头在圆形动画的外半径上旋转

[英]Arrow spinning on outer radius of circle animation

The idea is to have the arrow spin around the circle, on the outer radius. 想法是使箭头在外半径上绕圆旋转。 So the arrow has to stick to the outer radius and then follow the outer radius. 因此,箭头必须坚持外半径,然后跟随外半径。

It has to start spinning when I click a button 'start' and has to slow down and come to a stop after clicking a button 'stop' 单击“开始”按钮时它必须开始旋转,单击“停止”按钮后必须减速并停止

Current HTML 目前的HTML

<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="800px" height="800px">

  <path class="shape" fill="blue" d="
            M 100, 200 
            m 0 -100 
            a 100 100 0 1 0 1 0
            z
            m -1 25    
            a 75 75 0 1 1 -1 0     
            Z" />
</svg>

The circle + arrow 圆圈+箭头
https://codepen.io/tom-truyen/pen/KORgYX https://codepen.io/tom-truyen/pen/KORgYX

Insert the following below your donut svg: 在您的甜甜圈SVG下方插入以下内容:

    <script>
        var animate = false;
        var angle = 0;
        function tick() 
        { 
            document.querySelector(".arrow").setAttribute("style", "transform:translate(75px,175px) rotate("+angle+"deg) translate(0px,-112px);");
            angle += 1;
            if (animate) { window.requestAnimationFrame(tick); }
        }
    </script>

    <button onClick="window.animate=true;tick();">start</button>
    <button onClick="window.animate=false;">stop</button>

and change the arrow css to: 并将箭头css更改为:

    .arrow {
        height: 50px;
        width: 50px;
        position: absolute;
        transform:translate(75px,175px) translate(0px,-112px);
    }

That should do what you asked for. 那应该做您想要的。

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

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