-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
48 lines (40 loc) · 1.6 KB
/
demo.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
<html>
<head>Demo fabric canvas grab n move style</head>
<body>
<canvas id="id-of-your-canvas" width="500" height="500" style="border: black 1px solid;"></canvas>
<script src="http://underscorejs.org/underscore-min.js"></script>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.4.0/fabric.min.js"></script>
<script src="https://raw.githubusercontent.com/rstgroup/fabricjs-viewport/master/dist/fabricjs_viewport.js"></script>
<script src="fabricjs_fastcanvas.js"></script>
<script src="fabricjs_viewport_grabnmove.js"></script>
<script>
if (window.Workspace) {
var workspace = new Workspace("id-of-your-canvas")
workspace.enableGrabbing();
var canvas = workspace.scene;
var zoom=0;
var zoomUpdate = function (k){
zoom+=k;
canvas.setZoom(zoom);
console.log('zoom %s', zoom)
}
var el = canvas.upperCanvasEl;
var mousewheel = function (e) {
var e = window.event || e; // old IE support
var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail)));
zoomUpdate(delta/10)
}
if (el.addEventListener) {
el.addEventListener("mousewheel", mousewheel, false);
el.addEventListener("DOMMouseScroll", mousewheel, false)
}
else el.attachEvent("onmousewheel", mousewheel);
var triangle = new fabric.Triangle({
width: 100, height: 100, left: 50, top: 300, fill: '#cca'
});
canvas.add(triangle);
}
</script>
</body>
</html>