图片加载-从模糊到清晰

网页图片从模糊到清晰,可提升网页显示效果,增强用户体验感,具体代码如下。


复制下面代码后点我尝试运行

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
<!DOCTYPE html>
<html>
<head>
<title>大图片加载从模糊到清晰</title>
</head>
<body style="text-align:center">
<h3>大图片加载从模糊到清晰</h3>
<div class="mark" style='background-image:url(https://img.ssss.fun/2020/20200705135030.png);background-size:100%;
filter: blur(4px);transition: all 2.5s;width: 100%;height: 450px;margin-top: 20px;'>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
// 为了看到效果加个延时
setTimeout(function(){
// 若图片URL失效请自行替换
var imgUrl = 'https://img.ssss.fun/2020/20200705135030.png';
var imgObject = new Image();

imgObject.src = imgUrl;
imgObject.onload = function(){
$('.mark').css({
backgroundImage: 'url('+imgUrl+')',
filter: 'blur(0)'
});
}
}, 1000)

</script>
</body>
</html>