-
Notifications
You must be signed in to change notification settings - Fork 5
/
styring.html
95 lines (80 loc) · 1.99 KB
/
styring.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>
<style>
html, body {
margin: 0;
padding: 0;
}
.demo {
background: #f3eee6;
width: 300px;
height: 300px;
display: inline-block;
border-radius: 150px;
}
div {
display: inline-block;
}
.ball {
width: 100px;
height: 100px;
background: red;
position: absolute;
top: 100px;
left: 100px;
border-radius: 100px;
}
.ball.outline {
background: #eee;
}
.ball.ease {
-moz-transition: all 0.2s ease;
-o-transition: all 0.2s ease;
-webkit-transition: all 0.2s ease;
transition: all 0.2s ease;
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.js"></script>
<script src="js/pep.js"></script>
</head>
<body>
<div class='demo constrain-to-parent'>
<div class='ball outline'></div>
<div class='ball moveable'></div>
</div>
<div>
<p id="pos-x"></p>
<p id="pos-y"></p>
</div>
<script>
var REVERT_THRESHOLD = 1000;
var $ball = $('.ball.moveable');
var initialOffset = $ball.offset();
$('.ball').on("change mousemove touchmove", function() {
var offset = $ball.offset();
var offsetY = initialOffset.top - offset.top;
var offsetX = -1*(initialOffset.left - offset.left)
$('#pos-x').html('x: ' + offsetX + 'px');
$('#pos-y').html('y: ' + offsetY + 'px');
});
$ball.pep({
useCSSTranslation: false,
shouldEase: false,
constrainTo: 'parent',
initiate: function(){
this.$el.removeClass('ease')
},
stop: function(){
var offset = this.$el.offset();
var diffTop = initialOffset.top - offset.top;
var diffLeft = -1*(initialOffset.left - offset.left);
if ( diffTop < REVERT_THRESHOLD && diffLeft < REVERT_THRESHOLD ){
this.$el.css( initialOffset ).addClass('ease')
}
}
})
</script>
</body>
</html>