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围绕特定点旋转SVG对象`transform:rotate()`_Javascript_Svg_Rotation_Svg Animate - Fatal编程技术网

JavaScript围绕特定点旋转SVG对象`transform:rotate()`

JavaScript围绕特定点旋转SVG对象`transform:rotate()`,javascript,svg,rotation,svg-animate,Javascript,Svg,Rotation,Svg Animate,下面的代码运行正常,创建路径,并在单击时旋转它 我想围绕特定点旋转路径,当我使用下面的rotate(45 50 50)而不是rotate(x)时,我得到一个错误:VM267:85 Uncaught SyntaxError:missing)after参数列表我该怎么办 注意不想使用任何现成的库来处理任务,只需要使用标准API即可。谢谢 var NS=”http://www.w3.org/2000/svg"; var SVG=功能(el){ 返回文档。createElementNS(NS,el

下面的代码运行正常,创建路径,并在单击时旋转它

我想围绕特定点旋转路径,当我使用下面的
rotate(45 50 50)
而不是
rotate(x)
时,我得到一个错误:
VM267:85 Uncaught SyntaxError:missing)after参数列表
我该怎么办

注意不想使用任何现成的库来处理任务,只需要使用标准API即可。谢谢

var NS=”http://www.w3.org/2000/svg";  
var SVG=功能(el){
返回文档。createElementNS(NS,el);
}
svg=svg(“svg”);
setAttribute(“宽度”、“100%”);
setAttribute(“高度”、“100%”);
//svg.width='50em';//不起作用
document.body.appendChild(svg);
var bbox=svg.getBoundingClientRect();
变量中心={
x:bbox.left+bbox.width/2,
y:bbox.top+bbox.height/2
};
类myPath{
建造商(cx、cy){
this.path=SVG('path');
//  https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d
//  https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths
var d=“M”+cx+”+cy;
d=d+“L175 120 L125 120 Z”;
this.path.setAttribute(“d”,d);
this.path.setAttribute(“fill”,“#F7931E”);
this.path.addEventListener(“单击”,this,false);
}
获得抽签(){
返回此.path;
}
}
myPath.prototype.rotate=函数(x){
/*
var path=this.path.getBoundingClientRect();
变量Pc={
x:bbox.left+bbox.width/2,
y:bbox.top+bbox.height/2
};  */
返回svg.createSVGTransformFromMatrix(svg.createSVGMatrix().rotate(x));
// https://developer.mozilla.org/en/docs/Web/SVG/Attribute/transform
}
myPath.prototype.animate=函数(){
self=this.path;
self.transform.baseVal.appendItem(this.rotate(5));
};
myPath.prototype.handleEvent=函数(evt){
self=evt.target;
console.log(self.getAttribute('d');
self.move=setInterval(()=>this.animate(),100);
}

appendChild(新的myPath(center.x,center.y).draw)我可以使用
翻译(,)旋转来解决它(

var NS=”http://www.w3.org/2000/svg";  
var SVG=功能(el){
返回文档。createElementNS(NS,el);
}
svg=svg(“svg”);
setAttribute(“宽度”、“100%”);
setAttribute(“高度”、“100%”);
setAttribute(“填充”、“绿色”);
document.body.appendChild(svg);
bbox=svg.getBoundingClientRect();
中心={
x:this.bbox.left+this.bbox.width/2,
y:this.bbox.top+this.bbox.height/2
};
类myPath{
建造商(cx、cy){
this.path=SVG('path');
//  https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d
//  https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths
var d=“M”+cx+”+cy;
d=d+“h75 v75 h-75 z”;
this.path.setAttribute(“d”,d);
this.path.setAttribute(“fill”,“#F7931E”);
this.path.addEventListener(“单击”,this,false);
this.Pbox=svg.getBoundingClientRect();
此.Pc={
x:this.Pbox.left+this.Pbox.width/2,
y:this.Pbox.top+this.Pbox.height/2
};
}
获得抽签(){
返回此.path;
}
}
myPath.prototype.rotate=函数(x){
返回svg.createSVGTransformFromMatrix(svg.createSVGMatrix().rotate(x));
// https://developer.mozilla.org/en/docs/Web/SVG/Attribute/transform
}
myPath.prototype.move=函数(x,y){
返回svg.createSVGTransformFromMatrix(svg.createSVGMatrix().translate(x,y));
// https://developer.mozilla.org/en/docs/Web/SVG/Attribute/transform
}
myPath.prototype.animate=函数(){
self=this.path;
self.transform.baseVal.appendItem(this.move(this.Pc.x,this.Pc.y));
self.transform.baseVal.appendItem(this.rotate(5));
self.transform.baseVal.appendItem(this.move(-this.Pc.x,-this.Pc.y));
};
myPath.prototype.handleEvent=函数(evt){
self=evt.target;
console.log(self.getAttribute('d');
self.move=setInterval(()=>this.animate(),100);
}

appendChild(新的myPath(center.x,center.y).draw);
我能够使用
translate(,)rotate解决它(

var NS=”http://www.w3.org/2000/svg";  
var SVG=功能(el){
返回文档。createElementNS(NS,el);
}
svg=svg(“svg”);
setAttribute(“宽度”、“100%”);
setAttribute(“高度”、“100%”);
setAttribute(“填充”、“绿色”);
document.body.appendChild(svg);
bbox=svg.getBoundingClientRect();
中心={
x:this.bbox.left+this.bbox.width/2,
y:this.bbox.top+this.bbox.height/2
};
类myPath{
建造商(cx、cy){
this.path=SVG('path');
//  https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d
//  https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths
var d=“M”+cx+”+cy;
d=d+“h75 v75 h-75 z”;
this.path.setAttribute(“d”,d);
this.path.setAttribute(“fill”,“#F7931E”);
this.path.addEventListener(“单击”,this,false);
this.Pbox=svg.getBoundingClientRect();
此.Pc={
x:this.Pbox.left+this.Pbox.width/2,
y:this.Pbox.top+this.Pbox.height/2
};
}
获得抽签(){
返回此.path;
}
}
myPath.prototype.rotate=函数(x){
返回svg.createSVGTransformFromMatrix(svg.createSVGMatrix().rotate(x));
// https://developer.mozilla.org/en/docs/Web/SVG/Attribute/transform
}
myPath.prototype.move=函数(x,y){
返回svg.createSVGTransformFromMatrix(svg.createSVGMatrix().translate(x,y));
// https://developer.mozilla.org/en/docs/Web/SVG/Attribute/transform
}
myPath.prototype.animate=函数(){
self=this.path;
self.transform.baseVal.appendItem(this.move(this.Pc.x,this.Pc.y));
self.transform.baseVal.appendItem(this.rotate(5));
self.transform.baseVal.append
<path d="..." transform="rotate(45 50 50)" .../>
rotate(45, 50, 50)