-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path抛物线运动.html
56 lines (54 loc) · 1.05 KB
/
抛物线运动.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>抛物线运动</title>
<style>
div {
width: 100px;
height: 100px;
position: absolute;
left: 1000px;
top: 600px;
background-color: red;
}
</style>
</head>
<body>
<div></div>
<script src="js/$.js"></script>
<script>
"use strcit"
window.onload = function(){
var div = $('div')[0];
var timer = null;
document.onclick = function(e){
e = e || window.event;
clearInterval(timer);
var left = parseInt(css1(div,'left'));
var top = parseInt(css1(div,'top'));
var x = e.clientX-left ,
y = top-e.clientY,
b = (y+0.001*x*x)/x;
var l = 0, t= 0;
timer = setInterval(function(){
if(e.clientX > left){
l +=5;
if(l > x ){
clearInterval(timer);
}
}else if(e.clientX < left){
l -= 5;
if(l < x ){
clearInterval(timer);
}
}
t = -0.001*l*l+b*l;
div.style.left = l+left +'px';
div.style.top = top-t +'px' ;
},13)
}
}
</script>
</body>
</html>