-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
71 lines (68 loc) · 2.08 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Zoom Effect!</title>
<style>
body{
height: 100vh;
display: grid;
place-items: center;
background: #363942;
}
.zoom{
position: relative;
/* width: min(800px, 90vw);
height: 90vmin; */
width: 600px;
height: 400px;
border: 6px solid white;
/* box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); */
box-shadow: -1px 5px 15px #000;
overflow: hidden;
/* cursor: zoom-in; */
}
.zoom-img{
position: absolute;
width: 100%;
height: 100%;
-o-object-fit: cover;
object-fit: cover;
/* top: 50%;
left: 50%;
transform: translate(-50%, -50%) scale(1); */
transform: scale(var(--zoom, 1));
transform-origin: var(--x) var(--y);
transition: transform 0.3s ease;
display: block;
}
.zoom:hover{
--zoom: 2;
}
</style>
</head>
<body>
<main class="zoom">
<img src="OIP.jpg" alt="" class="zoom-img">
</main>
<script>
document.querySelectorAll('.zoom').forEach(elem => {
let x, y, width, height;
elem.onmouseenter = (e) => {
const size = elem.getBoundingClientRect();
x = size.x;
y = size.y;
width = size.width;
height = size.height;
};
elem.onmousemove = (e) => {
const horizontal = ((e.clientX - x) / width) * 100;
const vertical = ((e.clientY - y) / height) * 100;
elem.style.setProperty('--x', horizontal + '%');
elem.style.setProperty('--y', vertical + '%');
};
});
</script>
</body>
</html>