Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用setTimeout动态更改svg元素的属性不会';I don’我没有按预期工作_Javascript_Svg - Fatal编程技术网

Javascript 使用setTimeout动态更改svg元素的属性不会';I don’我没有按预期工作

Javascript 使用setTimeout动态更改svg元素的属性不会';I don’我没有按预期工作,javascript,svg,Javascript,Svg,我试图通过递归调用moveSelected函数,将SVG移动到X,Y。moveSelected功能依次将新的x和y设置得稍微靠近x,y,以再现动画效果 以下是我的功能: this.moveSelected = function moveSelected(moveToHex) { //setting new cords on screen var self=this; var repeater; var curX = parseInt(this.selectedE

我试图通过递归调用
moveSelected
函数,将SVG移动到X,Y。
moveSelected
功能依次将新的x和y设置得稍微靠近x,y,以再现动画效果

以下是我的功能:

this.moveSelected = function moveSelected(moveToHex) {
    //setting new cords on screen
    var self=this;
    var repeater;

    var curX = parseInt(this.selectedEle.getAttribute('cx'));
    var curY = parseInt(this.selectedEle.getAttribute('cy'));

    //console.log('curX '+curX+'curY ',curY);
    if(curX < moveToHex.cx) //moveRight
    {
        this.selectedEle.setAttribute('cx', curX + .5);
    }

    if(curX > moveToHex.cx) //moveLeft
    {
        this.selectedEle.setAttribute('cx',curX-.5);
    }

    if(curY < moveToHex.cy) //movedown
    {
        console.log('move down');
        this.selectedEle.setAttribute('cy', curY + .5);
    }

    if(curY > moveToHex.cy) //moveup
    {
        console.log('move Up');
        this.selectedEle.setAttribute('cy', curY - .5);
    }

    console.log('condition:' + curY + '<' + parseInt(moveToHex.cy));

    if((Math.abs(curY - moveToHex.cy)) < 1 &&
       (Math.abs(curX - moveToHex.cx) < 1)) {
        clearTimeout(repeater);
        unitArray[this.selectedUnit.num].hexagon = moveToHex;
        console.log('cleared');
    }
    else if(!repeater) {
        repeater = setTimeout(function() {
            self.moveSelected(moveToHex)
        }, 25); 
    }
}
this.moveSelected=函数moveSelected(moveToHex){
//在屏幕上设置新跳线
var self=这个;
var中继器;
var curX=parseInt(this.selectedEle.getAttribute('cx');
var curY=parseInt(this.selectedEle.getAttribute('cy');
//console.log('curX'+curX+'curY',curY);
if(curXmoveToHex.cx)//moveLeft
{
this.selectedEle.setAttribute('cx',curX-.5);
}
if(curYmoveToHex.cy)//moveup
{
console.log('move Up');
this.selectedEle.setAttribute('cy',curY-.5);
}

console.log('condition:'+curY+'
我不明白它为什么会这样做
…像什么?别让我们猜我的意思是为什么减法工作时它不会在curX或curY上加0.5这就像拔牙一样…它会做什么?是的,因为你解析它的行为是这样的-不要解析Damm!那很愚蠢,我很尴尬谢谢,谢谢