-
Notifications
You must be signed in to change notification settings - Fork 169
/
Copy pathviewport.html
95 lines (84 loc) · 3.16 KB
/
viewport.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
<!DOCTYPE html>
<html>
<head>
<!-- 必须强制指定页面编码为 UTF-8 -->
<meta charset="utf-8">
<!-- Demo 的简要说明,必须要填写 -->
<meta name="description" content="演示如何使用拖动,如何改变视野">
<!-- Demo 的作者,建议填写 -->
<meta name="author" content="[email protected]">
<!-- Demo 的标题,必须填写 -->
<title>拖动和视野控制</title>
<!-- Demo 开发过程中使用 CMD 引入 Kity 源码,方便调试 -->
<!-- dev start -->
<!-- 目录型的 Demo 注意修正源码引用路径 -->
<script src="../dev-lib/sea.js"></script>
<script>
// 设置好 kity 源代码目录
seajs.config( { base: '../src'} );
// 定义 Demo 模块
define('demo', function(require) {
var Class = require('core/class');
var Paper = require('graphic/paper');
var Shape = require('graphic/shape');
var Path = require('graphic/path');
var Grid = require('../demo/public/grid');
var Draggable = require('../demo/public/draggable');
Class.extendClass( Paper, Draggable );
Class.extendClass( Shape, Draggable );
var Rect = require('graphic/rect');
var paper = new Paper(document.body);
paper.setViewBox(-50, -50, 100, 100).drag();
paper.on('dragstart', function() {
this.setStyle('cursor', '-webkit-grabbing');
}).on('dragend', function() {
this.setStyle('cursor', '-webkit-grab');
}).trigger('dragend');
paper.addShape(new Grid(-1000, -1000, 2000, 2000, 10));
paper.addShape(new Rect(30, 30, 15, 15).pipe(function() {
this.fill('red');
this.scale(0.5);
this.drag();
this.setStyle('cursor', 'move');
}));
paper.addShape(new Path().pipe(function() {
var d = this.getDrawer();
d.moveTo(0, -10000).lineTo(0, 10000);
d.moveTo(-10000, 0).lineTo(10000, 0);
this.stroke('black', 1);
}));
window.addEventListener('mousewheel', function(e) {
//console.log("wheel", e);
e.preventDefault();
});
paper.on('click', function(e) {
console.log("down", e.getPosition().x, e.getPosition().y);
e.preventDefault();
});
document.body.addEventListener('mousewheel', function(e) {
var viewport = paper.getViewPort();
if(e.wheelDelta > 0) {
viewport.zoom = viewport.zoom * 0.95;
} else {
viewport.zoom = viewport.zoom / 0.95;
}
console.log(viewport);
paper.setViewPort(viewport);
});
});
</script>
<style>
body, html {
margin: 0;
padding: 0;
overflow: hidden;
height: 100%;
}
</style>
</head>
<body></body>
<script>
// 启动 Demo 模块
seajs.use('demo');
</script>
</html>