-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample.html
More file actions
98 lines (83 loc) · 2.83 KB
/
example.html
File metadata and controls
98 lines (83 loc) · 2.83 KB
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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>jquery-behavior example</title>
<style>
div {
position: absolute;
width: 40px;
height: 40px;
background-color: red;
}
</style>
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="./jquery.behavior.js"></script>
<script>
$(function () {
var bhvrWait = $.Behavior();
bhvrWait('div').on('mousedown', function (e) {
bhvrWait.stop();
var $div = $(this);
var offset = $div.offset();
bhvrDrag.start({
$div: $div,
offsetX: offset.left - e.pageX,
offsetY: offset.top - e.pageY
});
});
var $draggable;
var offsetX, offsetY;
var bhvrDrag = $.Behavior({
active: false,
onStart: function (data) {
offsetX = data.offsetX;
offsetY = data.offsetY;
$draggable = data.$div;
}
});
bhvrDrag(document).on('mousemove', function (e) {
$draggable.css({
left: e.pageX + offsetX,
top: e.pageY + offsetY
});
});
bhvrDrag(document).on('mouseup', function (e) {
bhvrDrag.stop();
bhvrWait.start();
});
});
</script>
</head>
<body>
<div style="left: 80px; top: 0px;"></div>
<div style="left: 120px; top: 0px;"></div>
<div style="left: 160px; top: 0px;"></div>
<div style="left: 200px; top: 0px;"></div>
<div style="left: 240px; top: 0px;"></div>
<div style="left: 40px; top: 40px;"></div>
<div style="left: 0px; top: 80px;"></div>
<div style="left: 0px; top: 120px;"></div>
<div style="left: 0px; top: 160px;"></div>
<div style="left: 0px; top: 200px;"></div>
<div style="left: 40px; top: 240px;"></div>
<div style="left: 80px; top: 280px;"></div>
<div style="left: 120px; top: 280px;"></div>
<div style="left: 160px; top: 280px;"></div>
<div style="left: 200px; top: 280px;"></div>
<div style="left: 240px; top: 280px;"></div>
<div style="left: 280px; top: 240px;"></div>
<div style="left: 320px; top: 200px;"></div>
<div style="left: 320px; top: 160px;"></div>
<div style="left: 320px; top: 120px;"></div>
<div style="left: 320px; top: 80px;"></div>
<div style="left: 280px; top: 40px;"></div>
<div style="left: 120px; top: 80px;"></div>
<div style="left: 200px; top: 80px;"></div>
<div style="left: 80px; top: 160px;"></div>
<div style="left: 120px; top: 200px;"></div>
<div style="left: 160px; top: 200px;"></div>
<div style="left: 200px; top: 200px;"></div>
<div style="left: 240px; top: 160px;"></div>
</body>
</html>