-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove1.html
116 lines (102 loc) · 2.14 KB
/
move1.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<style>
*{
margin: 0;
padding: 0;
}
.small{
width: 360px;
height: 240px;
float: left;
margin-right: 100px;
position: relative;
}
.zhezhao{
width: 30px;
height: 20px;
position: absolute;
left: 0;
top: 0;
background: rgba(0, 0, 0, 0.5)
}
.fugai{
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
z-index: 99;
}
.small img{
width: 100%;
height: 100%;
}
.big{
width: 360px;
height: 240px;
float: left;
overflow: hidden;
position: relative;
}
.big img{
position: absolute;
left: 0;
top: 0;
}
</style>
<body>
<div class="small">
<div class="fugai"></div>
<img src="google-earth-view-2430.jpg" alt="">
</div>
<div class="zhezhao"></div>
<div class="big"><img src="google-earth-view-2430.jpg" alt=""></div>
</body>
<script>
let zhezhao =document.querySelector('.zhezhao');
let small =document.querySelector('.small');
let big =document.querySelector('.big img');
let zzw=zhezhao.offsetWidth
zzh=zhezhao.offsetHeight
sw=small.offsetWidth
sh=small.offsetHeight
bw=big.offsetWidth
bh=big.offsetHeight
small.onmousemove=function(e){
let ox=e.offsetX-zzw/2 ,oy=e.offsetY-zzh/2;
if(ox>=sw-zzw){
ox=sw-zzw
}
if(ox<=0){
ox=0
}
if(oy>=sh-zzh){
oy=sh-zzh
}
if(oy<=0){
oy=0
}
zhezhao.style.left=`${ox}px`
zhezhao.style.top=`${oy}px`
big.style.width=`${sw*sw/zzw}px`
big.style.heigth=`${sh*sh/zzh}px`
big.style.left=`${-ox*sw/zzw}px`
big.style.top=`${-oy*sh/zzh}px`
console.log(big.style.left)
console.log(big.style.top)
// console.log(big.style.left>='-500px')
// console.log(big.style.left)
// if(big.style.left>='-500px'){
// big.style.left='-500px'
// }
// if(big.style.top>='-300px'){
// big.style.top='-300px'
// }
}
</script>
</html>