//创建元素连接线。必须依赖jquery组件。生成的连接线由3部分组件包括第一段连接线(它负责与源元素连接)、第二段连接线(它负责与第一段连接线和连接点连接)、连接点(它负责与目标元素连接,但不是必须的。它没有连接点时,由第二段连接线直接与目标元素连接) //参数 // $ele:连接线的显示容器对象 // opt:创建参数对象{} // x: int。第一段连接线相对显示容器的left位置。单位为px,默认为200。 // y: int。第一段连接线相对显示容器的top位置。单位为px,默认为100。 // h: int。第一段连接线长度。单位为px,默认为100。 // color: string。所有连接线颜色,默认为"red"。 // rotate: int。第一段连接线旋转角度。支持顺时针(正数)和逆时针(负数),默认为20度。 // weight: int。连接线粗细。单位为px,默认为1px。 // line2Width: int。第二段连接线长度。单位为px,默认为第一段长度一半。 // endpointSize: int。连接点大小。单位为px。小于等于0时将不显示连接点。 // endpointColor: string。连接点颜色,默认为连接线颜色。当endpointSize>0时生效。 //方法 // new: 实例化。返回连接线对象。 // Hide(): 隐藏并销毁连接线。 //属性 // linkline1: 第一段连接线jquery对象。为null表示连接线生成失败。 // linkline2: 第一段连接线jquery对象。。为null表示连接线生成失败。 // endpoint: 连接点jquery对象。为null表示没有连接点。 // zIndex: 只读。 // id: 只读。 //调用实例参考 // var exmpline=new linkline($("body"),{}); // var line1=new linkline($("body"),{x:200,y:100,h:200,line2Width:20,color:"#999",rotate:25,weight:1,endpointSize:10,endpointColor:"#999"}); function linkline($ele, opt) { this.opt = $.extend({ x: 200, y: 100, h: 100, color: "red", line2Width: 0, rotate: 20, weight: 1, endpointSize: 0, endpointColor: "red" }, opt); this.zIndex = (new Date().getTime() + "").substring(3, 13) * 1; this.id = this.opt.x + this.opt.y + this.opt.h + this.opt.line2Width + this.opt.rotate; this.linkline1 = null; this.linkline2 = null; this.endpoint = null; this.create = function() { if ($("#linkline_" + this.id + "_1").length > 0) { return false; } var line1 = "
"; $ele.append(line1); this.linkline1 = $("#linkline_" + this.id + "_1"); var addWeight = this.opt.weight / 2; var line2xy = rotatePoint({ x: this.opt.x + addWeight, y: this.opt.y - addWeight }, { x: this.opt.x + addWeight, y: this.opt.y - addWeight + this.opt.h / 2 }, this.opt.rotate); var line2W = this.opt.line2Width > 0 ? this.opt.line2Width : this.opt.h / 2; var line2Left = this.opt.rotate >= 0 ? line2xy.x : line2xy.x - line2W; var line2 = "