今天小編和大家分享有關(guān)于:“怎么使用html+css實(shí)現(xiàn)圖片掃描儀特效?”這個(gè)問(wèn)題的相關(guān)解決方法和實(shí)現(xiàn)的代碼,希望對(duì)大家的學(xué)習(xí)有所幫助!
效果:
這樣,有抖動(dòng)的:
無(wú)抖動(dòng)的:
實(shí)現(xiàn):
1.定義一個(gè)盒子:
<body>
<div class="tu"></div>
</body>
2.基本樣式,長(zhǎng)寬背景圖等等~
.tu{
width: 500px;
height: 300px;
background-image: url(8.jpg);
background-size: 100% auto;
background-repeat: no-repeat;
position: relative;
overflow: hidden;
cursor: pointer;
}
cursor: pointer;鼠標(biāo)經(jīng)過(guò)盒子樣式為小手
3.用偽類元素做掃描線,基本樣式:
.tu::after{
content: '';
position: absolute;
top: 0;
left: 0;
width: 500px;
height: 35px;
background-image: url(8.jpg);
background-size: 100% auto;
background-repeat: no-repeat;
filter: sepia(100%);
opacity: 0;
}
filter: sepia(100%); 圖片發(fā)黃。
filter: invert(100%); 像X光底片。
4.實(shí)現(xiàn)掃描:
.tu:hover::after{
opacity: 1;
animation: move 1.8s linear infinite;
}
@keyframes move{
0%{
top: 0;
background-position: 6px 0px;
}
20%{
top: 60px;
background-position: -6px -60px;
}
40%{
top: 120px;
background-position: 6px -120px;
}
60%{
top: 180px;
background-position: -6px -180px;
}
80%{
top: 240px;
background-position: 6px -240px;
}
100%{
top: 300px;
background-position: -6px -300px;
}
}
讓background-position的y軸位移剛好等于top的距離,然后x軸為0的話就不抖,有數(shù)值就會(huì)抖動(dòng)。
完整代碼:
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: rgb(0, 0, 0);
}
.tu{
width: 500px;
height: 300px;
background-image: url(8.jpg);
background-size: 100% auto;
background-repeat: no-repeat;
position: relative;
overflow: hidden;
cursor: pointer;
}
.tu::after{
content: '';
position: absolute;
top: 0;
left: 0;
width: 500px;
height: 20px;
background-image: url(8.jpg);
background-size: 100% auto;
background-repeat: no-repeat;
filter: invert(100%);
opacity: 0;
}
.tu:hover::after{
opacity: 1;
animation: move 1.8s linear infinite;
}
@keyframes move{
0%{
top: 0;
background-position: 6px 0px;
}
20%{
top: 60px;
background-position: -6px -60px;
}
40%{
top: 120px;
background-position: 6px -120px;
}
60%{
top: 180px;
background-position: -6px -180px;
}
80%{
top: 240px;
background-position: 6px -240px;
}
100%{
top: 300px;
background-position: -6px -300px;
}
}
</style>
</head>
<body>
<div class="tu"></div>
</body>
</html>
總結(jié):
這是網(wǎng)上看到一外國(guó)博主的創(chuàng)意,然后自己也弄了一個(gè),雖然效果是比較簡(jiǎn)單的,但也是挺好玩的~
那么以上的內(nèi)容就是有關(guān)于:“怎么使用html+css實(shí)現(xiàn)圖片掃描儀特效?”這個(gè)問(wèn)題的全部?jī)?nèi)容,更多有關(guān)于html5這方面的相關(guān)內(nèi)容我們都可以在W3Cschool中進(jìn)行學(xué)習(xí)和了解!