图片扫描仪特效 html+css
【摘要】 效果:
这样,有抖动的: 无抖动的:
实现:
1.定义一个盒子:
<body> <div class="tu"></div>
</body>
123
2.基本样式,长宽背景图等等~
.tu{ width: 500px; height: 300px; background-image: url(8.jpg); background-size: 100% ...
效果:
这样,有抖动的:
无抖动的:
实现:
1.定义一个盒子:
<body> <div class="tu"></div>
</body>
- 1
- 2
- 3
2.基本样式,长宽背景图等等~
.tu{ width: 500px; height: 300px; background-image: url(8.jpg); background-size: 100% auto; background-repeat: no-repeat; position: relative; overflow: hidden; cursor: pointer; }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
cursor: pointer;鼠标经过盒子样式为小手
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; }
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
filter: sepia(100%); 图片发黄。
filter: invert(100%); 像X光底片。
4.实现扫描:
.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; } }
- 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
让background-position的y轴位移刚好等于top的距离,然后x轴为0的话就不抖,有数值就会抖动。
完整代码:
<!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>
- 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
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
总结:
这是网上看到一外国博主的创意,然后自己也弄了一个,虽然效果是比较简单的,但也是挺好玩的~
文章来源: blog.csdn.net,作者:北极光之夜。,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/luo1831251387/article/details/111570536
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)