Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/392.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.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路径中的箭头不起作用_Javascript_Jquery_Svg - Fatal编程技术网

Javascript 动态绘制svg路径中的箭头不起作用

Javascript 动态绘制svg路径中的箭头不起作用,javascript,jquery,svg,Javascript,Jquery,Svg,var-Belay=(函数(){ 变量设置={ strokeColor:“#fff”, 冲程宽度:2, 不透明度:1, 填写:'无', 动画:对, animationDirection:'右', 动画持续时间:.75 }; var me={}; me.init=函数(initObj){ if(initObj){ $.each(initObj,函数(索引,值){ //设置上的TODO验证 设置[索引]=值; }); } } me.set=函数(prop,val){ //TODO验证 设置[prop

var-Belay=(函数(){
变量设置={
strokeColor:“#fff”,
冲程宽度:2,
不透明度:1,
填写:'无',
动画:对,
animationDirection:'右',
动画持续时间:.75
};
var me={};
me.init=函数(initObj){
if(initObj){
$.each(initObj,函数(索引,值){
//设置上的TODO验证
设置[索引]=值;
});
}
}
me.set=函数(prop,val){
//TODO验证
设置[prop]=val;
}
me.on=函数(el1,el2){
变量$el1=$(el1);
变量$el2=$(el2);
如果($el1.length&$el2.length){
var svgheight、p、svgleft、svgtop、svgwidth
var el1pos=$(el1.offset();
var el2pos=$(el2.offset();
var el1H=$(el1.outerHeight();
var el1W=$(el1).outerWidth();
var el2H=$(el2.outerHeight();
var el2W=$(el2).outerWidth();
var node1X=数学圆整(左前1个角+左前1个角);
var node2X=数学圆(左el2pos);
var重叠=节点1x>=节点2x;
var svgwidth=Math.abs(node2X-node1X);
var svgleft=数学最小值(节点1x、节点2x);
var node1Y=数学圆整(el1pos.top+el1H/2);
var node2Y=数学圆整(el2pos.top+el1H/2);
var svgheight=Math.abs(node1Y-node2Y);
var svgtop=数学最小值(node1Y,node2Y);
var pt1x=节点1x-svgleft;
var pt1y=node1Y-svgtop+settings.strokeWidth;
var pt2x=节点2x-svgleft;
var pt2y=node2Y-svgtop+settings.strokeWidth;
//cpt是控制点向量的长度
//带距离网络框的variew
var cpt=数学圆(svgwidth*Math.min(svghight/300,1));
如果(重叠){
//需要加宽svg,否则会影响bezier控件
//点(因此曲线)将延伸到其外部。
svgleft-=cpt;
svgwidth+=2*cpt;
pt1x+=cpt;
pt2x+=cpt;
}
//建立路径描述
p=“M”+pt1x+,“+pt1y+
“L”+(pt1x+pt2x)/8+”,“+pt1y+
“L”+(pt1x+pt2x)/8+”,“+pt2y//+
“L”+(pt2x)/1.03+”,“+pt2y+
“L”+(pt2x)/1.03+”,“+(pt2y-5)+
“L”+pt2x+,“+pt2y”+
“L”+(pt2x)/1.03+”,“+(pt2y+5)+
“L”+(pt2x)/1.03+”,“+pt2y;
//丑陋的一行
$ropebag=$('#ropebag')。长度?$('#ropebag'):$('body')。追加($(“”)。查找('#ropebag');
var svgnode=document.createElements('http://www.w3.org/2000/svg'、'svg');
var defs=document.createElements('http://www.w3.org/2000/svg","defs";;
var marker=document.createElements('http://www.w3.org/2000/svg","标记";;
var path=document.createElements('http://www.w3.org/2000/svg","路径";;
setAttributeNS(null,“id”,“arrow”);
marker.setAttributeNS(null,“markerWidth”,“13”);
marker.setAttributeNS(空,“markerHeight”,“13”);
setAttributeNS标记(null,“refX”,“2”);
标记。刚毛属性(空,“参考”,“7”);
setAttributeNS(null,“markerUnits”、“userSpaceOnUse”);
setAttributeNS(null,“d”,“M2,2l2,13l8,7l2,2”);
marker.appendChild(路径);
定义追加子项(标记);
var newpath=document.createElements('http://www.w3.org/2000/svg","路径";;
setAttributeNS(null,“d”,p);
setAttributeNS(空,“笔划”,settings.strokeColor);
setAttributeNS(null,“笔划宽度”,settings.strokeWidth);
setAttributeNS(null,“不透明度”,settings.opacity);
newpath.setAttributeNS(null,“fill”,settings.fill);
setAttributeNS(null,“标记结束”,“url(#箭头)”);
svgnode.appendChild(newpath);
附加子对象(defs);
$(svgnode).css({
左:svgleft,
顶部:svgtop-settings.strokeWidth,
位置:'绝对',
宽度:svgwidth,
高度:svgheight+settings.strokeWidth*2,
最小高度:“20px”,
“指针事件”:“无”
});
$ropebag.append(svgnode);
如果(设置。动画){
//多亏了http://jakearchibald.com/2013/animated-line-drawing-svg/
var pl=newpath.getTotalLength();
//设置起始位置
newpath.style.strokeDasharray=pl+''+pl;
如果(settings.animationDirection=='right'){
newpath.style.strokedashcoffset=pl;
}否则{
newpath.style.strokedashcoffset=-pl;
}
//触发布局,以便在浏览器中计算样式
//在设置动画之前拾取起始位置
//在IE中不起作用。如果需要,请使用requestAnimationFrame来更新,而不是CSS动画
newpath.getBoundingClientRect();
newpath.style.transition=newpath.style.WebkitTransition='stroke dashoffset'+settings.animationDuration+'s ease in out';
//走!
newpath.style.strokeDashoffset='0';
}
}
}
me.off=函数(){
$(“#ropebag”).empty();
}
还我;
}());
/***********************自定义JavaScript**********************************/
$(文档).ready(函数(){
$(“.draggable”).draggable({
拖动: