给大家分享一个用CSS 3.0图片像素放大实现的马赛克特效,效果如下:
以下是代码实现,欢迎大家复制粘贴和收藏。
代码语言:javascript复制<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS 3.0图片像素放大马赛克特效</title>
<style>
* {
margin: 0;
padding: 0;
font-family: '微软雅黑', sans-serif;
}
body {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
background: #000;
}
.container {
position: relative;
width: 900px;
display: flex;
align-items: center;
justify-content: space-between;
}
.container .pixel {
position: relative;
width: 400px;
height: 400px;
background: #000;
}
.container .pixel img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
/* 关键属性 */
image-rendering: pixelated;
}
.container .pixel img:last-child {
transition: 2s;
}
.container .pixel:hover img:last-child {
transition: 2s;
opacity: 0;
}
</style>
</head>
<body>
<div class="container">
<div class="pixel">
<img src="img1_400x400.jpg">
<img src="img1_20x20.jpg">
</div>
<div class="pixel">
<img src="img2_400x400.jpg">
<img src="img2_20x20.jpg">
</div>
</div>
</body>
</html>
以下是代码中所引用的图片。
img1_20x20.jpg
img2_20x20.jpg
img1_400x400.jpg
img2_400x400.jpg