mac鱼眼效果

2022-05-23

前端

人不能象走兽那样活着,应该追求知识和美德。——但丁

上代码,上效果:

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
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}

#wrapper {
position: absolute;
bottom: 0;
text-align: center;
width: 100%;
}

#wrapper>img {
border-radius: 50%;
}
</style>
</head>

<body>

<div id="wrapper">
<img src="/imgs/oss/2020-06-01/head.jpg" width="64">
<img src="/imgs/oss/2020-06-01/head.jpg" width="64">
<img src="/imgs/oss/2020-06-01/head.jpg" width="64">
<img src="/imgs/oss/2020-06-01/head.jpg" width="64">
<img src="/imgs/oss/2020-06-01/head.jpg" width="64">
</div>
<script>


window.onload = function () {
document.onmousemove = function (ev) {
var oevent = ev || event;
var aimg = document.getElementsByTagName('img');
var odiv = document.getElementById('wrapper');
for (var i = 0; i < aimg.length; i++) {
var x = aimg[i].offsetLeft + aimg[i].offsetWidth / 2;
var y = aimg[i].offsetTop + odiv.offsetTop + aimg[i].offsetHeight / 2;
var a = x - oevent.clientX;
var b = y - oevent.clientY;
var dis = parseInt(Math.sqrt(a * a + b * b));
var scale = 1 - dis / 200;
if (scale < 0.5) {
scale = 0.5;
}
aimg[i].width = scale * 128;
}
}
}

</script>
</body>

</html>

效果:

fisheye