【问题标题】:Twojs blinking circleTwojs 闪烁的圆圈
【发布时间】:2018-09-23 22:19:33
【问题描述】:

我正在开发一个图形编辑器。我需要突出显示一个圆圈,并在屏幕中心制作该圆圈并将缩放比例设置为 2。如果该圆圈已被高亮显示,请将其切换并设置为普通圆圈。我需要至少让圆圈闪烁才能将其关闭。

我不知道如何让圆圈闪烁。知道“two.js”怎么做的人可以吗?我知道它在函数 two.update();

    // Render loop
var temps = 0;
two.bind('update', function(){
    if  (selectedNodes.length > 0){
        if (temps > 0) {    
            temps -= 0.02;
            for(var i = 0; i < selectedNodes.length; i++){
                selectedNodes[i].circle.fill = 'yellow';
                selectedNodes[i].circle.scale = 1.3;
                selectedNodes[i].circle.stroke = "red";
                selectedNodes[i].circle.linewidth = 2;
            }
        } else {
            for(var i = 0; i < selectedNodes.length; i++){
                selectedNodes[i].circle.fill = '#FF8000';
                selectedNodes[i].circle.scale = 1;
                selectedNodes[i].circle.noStroke();
            }
        }
    }
});

并触发眨眼

function Blink(){
    temps = 1;
}

这是最好的闪烁方式吗(即使它只闪烁一次)

这是一个 JsFiddle https://jsfiddle.net/hichem147/uf0b82ry/

要使用它:点击[(+)节点],然后创建一些节点,然后点击[选择]并点击一个圆圈,然后点击[闪烁]按钮。

【问题讨论】:

    标签: javascript graph editor two.js


    【解决方案1】:

    最后,我使用了 setTimeout 和 setInterval

        function MakeCircleBlink(){
          var count = 5;
    
          if (count > 0) {
             var x = setInterval(function(){ 
                count--;
                console.log(count);
                if (count ===0) {clearInterval(x);}
                blink(); 
              }, 1000);  
    
    
          }  
        }
    
        function blink(n){
          n--;
        circle1.stroke = 'red';
        circle1.linewidth = 4;
        circle1.scale = 1.0;
    
        setTimeout(function(){ circle1.noStroke(); circle1.scale = 1;}, 500);
        }
    

    这是一个代码笔,展示了它是如何工作的:https://codepen.io/hichem147/pen/jvjKzP?editors=0010

    【讨论】:

      猜你喜欢
      • 2015-01-30
      • 1970-01-01
      • 2022-12-21
      • 1970-01-01
      • 1970-01-01
      • 2012-12-10
      • 2019-09-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多