-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackgroundtrans.html
92 lines (88 loc) · 2.05 KB
/
backgroundtrans.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
.container{
width: 100%;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: #f3fbff;
}
.img-box{
width: 60%;
height: 33%;
margin: auto;
line-height: 0;
background-image: url("background.png");
overflow: hidden;
position: relative;
}
/* .img-box img{
width: 100%;
height: 330px;
} */
.img-wrap{
position: absolute;
top: 0;
left: 0;
overflow: hidden;
}
span{
width: 1px;
height: 100%;
cursor: pointer;
background-color: #fff;
position: absolute;
top: 0;
left: 0;
}
#arrow{
width: 40px;
position: absolute;
top: 50%;
margin-left: -20px;
margin-right: -20px;
}
#original{
width: 200%;
}
</style>
</head>
<body>
<div class="container">
<div class="img-box" id="img-box">
<img src="transparent.png" width="100%">
<div class="img-wrap" id="img-wrap">
<img src="original.jpg" id="original">
</div>
<span id="line">
<img src="arrow.png" id="arrow">
</span>
</div>
</div>
<script>
var transImg = document.getElementById("img-box");
var orgImg = document.getElementById("img-wrap");
var original = document.getElementById("original");
var line = document.getElementById("line");
var prevMouseX = 0;
original.style.width = transImg.offsetWidth + "px";
var leftSpace = transImg.offsetLeft;
transImg.onmousemove = function(e){
var boxWidth = (e.pageX - leftSpace) + "px";
orgImg.style.width = boxWidth;
line.style.left = boxWidth;
}
</script>
</body>
</html>