-
Notifications
You must be signed in to change notification settings - Fork 1
/
ch03r01.html
37 lines (34 loc) · 919 Bytes
/
ch03r01.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
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css">
#square {
width: 100px;
height: 100px;
background-color: #ccc;
position: absolute;
}
</style>
</head>
<body>
<div id="main">
<div id="square">
</div>
</div>
<script src="http://code.jquery.com/jquery-1.5.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0a4.1/jquery. mobile-1.0a4.1.min.js"></script>
<script type="text/javascript">
$('#square').bind("touchmove", function(e) {
e.preventDefault();
var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
var elm = $(this).offset();
var x = touch.pageX - elm.left/2;
var y =touch.pageY - elm.top/2;
$(this).css('left', x + 'px');
$(this).css('top', y + 'px');
});
</script>
</body>
</html>