黑松山资源网 Design By www.paidiu.com
CSS 实现 图片鼠标悬停折叠效果
1. 实现要点
- 折叠是由多个块级元素来完成的;
- 图片是以背景图片的方式呈现出来的;
- 给每个块级元素设置同一张背景图片,通过background-position来控制显示的区域(类似于雪碧图);
- 通过ransform属性来实现折叠效果;
- 整个包裹div的大小就是图片的原大小,如果更改了尺寸,需要调整background-size等属性调整背景图片大小
2. 效果展示
3. 源码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>hover-folder</title> <style> html, body, ul, li { margin: 0; padding: 0 } ul { list-style: none; display: block; } body { width: 100%; height: 100vh; } .container { width: 100%; height: 100%; /* background-color: aqua; */ display: flex; justify-content: center; align-items: center; transform: scale(0.5); } .wrap { box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .5); width: 1280px; height: 854px; font-size: 0; line-height: 0; position: relative; } .image { cursor: pointer; } .abs-wrap { height: 100%; width: 100%; /* top: 0; left: 0; */ /* position: absolute; */ z-index: 10; } .abs-wrap:hover>.abs:nth-child(2) { transform: matrix(0.8, -0.2, 0, 1, -1, 0); } .abs-wrap:hover>.abs:nth-child(3) { transform: matrix(0.8, 0.2, 0, 1, -53, -50); } .abs-wrap:hover>.abs:nth-child(4) { transform: matrix(0.8, -0.2, 0, 1, -105, 0); } .abs-wrap:hover>.abs:nth-child(5) { transform: matrix(0.8, 0.2, 0, 1, -157, -50); } .abs { transform-style: preserve-3d; transform-origin: left center; transition: .4s ease-in-out; width: 20%; height: 100%; /* background-color: rgba(0, 0, 0, .5); */ display: inline-block; background-size: 100%; background: url('https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1600577868615&di=d2979a54604ecb409e3329527d0220fa&imgtype=0&src=http%3A%2F%2Ft9.baidu.com%2Fit%2Fu%3D29311073%2C358824429%26fm%3D79%26app%3D86%26f%3DJPEG%3Fw%3D1280%26h%3D854'); } .abs:nth-child(1) { background-position: 0% 0%; } .abs:nth-child(2) { background-position: 25% 0%; } .abs:nth-child(3) { background-position: 50% 0%; } .abs:nth-child(4) { background-position: 75% 0%; } .abs:nth-child(5) { background-position: 100% 0%; } </style> </head> <body> <div class="container"> <div class="wrap"> <ul class="abs-wrap"> <li class="abs"></li> <li class="abs"></li> <li class="abs"></li> <li class="abs"></li> <li class="abs"></li> </ul> </div> </div> </body> </html>
总结
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
更新日志
2024年09月20日
2024年09月20日
- 《神话时代:重述版》评测:粉丝们的朝花夕拾
- 战锤40K星际战士2先锋职业介绍|先锋职业技能效果一览
- 战锤40K星际战士2重装职业介绍|重装职业技能效果一览
- 交错战线能源发电站推荐角色一览
- 阿波罗乐神之音《第4集出埃及记》[WAV+CUE]
- JohnWrightTrio-SouthSideSoul-1960-2024(24-192)
- AnthonyBruno-Cefalu(2024)[24-96]
- 《地狱潜者2》玩家人数飙升:终于不再削弱玩家了
- 黑神话引力!外媒分享孙悟空英文书籍:美生中国人等
- 《荒野大镖客》PC版曝光!《GTA6》疑似也有PC版
- 林宥嘉.2008-神秘嘉宾(引进版)【华研国际】【WAV+CUE】
- 徐小凤.1997-金曲精选(康艺经典珍藏系列)【康艺成音】【WAV+CUE】
- 群星.1994-非常精丫宝丽金】【WAV+CUE】
- 《赛马娘 热血喧闹大感谢祭!》评测:现代复古派对
- 《星球大战:亡命之徒》评测:还是看看远方的光剑吧