-
Notifications
You must be signed in to change notification settings - Fork 0
/
move.html
50 lines (43 loc) · 910 Bytes
/
move.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
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
.demo-div {
width: 100px;
height: 100px;
border-radius: 100px;
background: yellowgreen;
position: absolute;
left: 0;
top: 0;
}
</style>
<script type="text/javascript">
window.onload = function() {
var oDiv = document.getElementsByClassName('demo-div')[0]
var timer = null
move(oDiv, 5)
function move(element, time) {
var l = element.offsetLeft
var t = element.offsetTop
var start = 1
clearInterval(timer)
console.log('l:', l)
console.log('t:', t)
console.log('start move from l: ', l, ' top: ', top)
setTimeout(() => {
clearInterval(timer)
}, time * 1000)
timer = setInterval(function() {
element.style.left = element.offsetLeft + start + 'px'
start *= 1.1
}, 100)
}
}
</script>
</head>
<body>
<div class="demo-div"></div>
</body>
</html>