-
Notifications
You must be signed in to change notification settings - Fork 0
/
14-line-虚线.html
104 lines (72 loc) · 2.26 KB
/
14-line-虚线.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" type="text/css" href="svg270/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="svg270/themes/icon.css">
<script type="text/javascript" src="svg270/jquery.min.js"></script>
<script type="text/javascript" src="svg270/jquery.easyui.min.js"></script>
<!--高版本-->
<script src="svg311/node_modules/@svgdotjs/svg.js/dist/svg.js"></script>
<script src="svg311/node_modules/@svgdotjs/svg.panzoom.js/dist/svg.panzoom.js"></script>
<script src="svg311/node_modules/@svgdotjs/svg.draggable.js/dist/svg.draggable.js"></script>
</head>
<style>
</style>
<!--
-->
<body>
<div id="drawing" style="border:2px solid green;width: 800px;height: 600px;">
</div>
</body>
<script>
class Point{
constructor(x, y) {
this.x = x;
this.y = y;
}
}
var draw = initDrawing();
let startP = new Point(10,20);
let endP = new Point(10,100);
var line = draw.line(startP.x,startP.y,endP.x,endP.y).css({"stroke-width":1,"stroke":"red"}).addClass("c1")
line.css({"stroke-dasharray":"5,5"});
//画起点
draw.circle(1).css({"fill":"green"}).move(startP.x,startP.y);
//通过demo 可知:视觉上,起点是一定会有线与其相连的,但终点不能保证一定有线段相连
draw.circle(1).css({"fill":"blue"}).move(endP.x,endP.y);
/**
初始化画布
*/
function initDrawing(){
//测试证明 外部的 div 也不能用 数字开头,不然报【 is not a valid selector】
var drawingId = "drawing";
//高版本
var draw = SVG().addTo('#'+drawingId).size("100%", "100%");
// pan and zoom
//动态计算 viewbox内部的值
let width = $('#' + drawingId).width();
let height = $('#' + drawingId).height();
draw.viewbox('0 0 '+width+' '+height).panZoom({ zoomMin: 0.5, zoomMax: 20 });
return draw;
}
function createUUID() {
var x = 13 * Math.floor(Math.random() * 1000) + "-" + 7 * Math.floor(Math.random() * 100);
return "id_" + x;
}
/**
* 生成随机颜色
*/
function getRandomColor() {
var x = getRandomInteger();
return "#" + x;
}
/**
* 生成随机数
*/
function getRandomInteger() {
var x = Math.floor(Math.random() * 9) + "" + Math.floor(Math.random() * 9) + "" + Math.floor(Math.random() * 9);
return x;
}
</script>
</html>