图片悬停“滑动打开”动画效果

栏目: Html · 发布时间: 7年前

核心属性

overflow: hidden “滑动打开”时将超出矩形范围的图片裁剪掉

background-size: cover 背景图完全覆盖背景区域,但是可能会有部分看不到

clip-path 裁剪图片(road-to-nowhere.jpg)分别为上下两部分

hover + transition + transform: translateY( ) 鼠标悬停时图片分别上下移动自身高度的45%距离

相关知识

《CSS3/SVG clip-path路径剪裁遮罩属性简介》

  1. <base href="https://pics.codecolor.cn/sliding-door-images/">
  2. <figure>
  3. <figcaption><div>路无尽头</div><div>脚不停止</div></figcaption>
  4. <img src="road-to-nowhere.jpg" alt="">
  5. <img src="road-to-nowhere.jpg" alt="">
  6. </figure>
  1. * {
  2. box-sizing: border-box;
  3. }
  4. body {
  5. margin: 0;
  6. background: #222;
  7. }
  8. figure {
  9. position: relative;
  10. width: 60vw;
  11. height: 60vw;
  12. margin: 0 auto;
  13. overflow: hidden;
  14. background-image: url(https://pics.codecolor.cn/sliding-door-images/mad-dog.jpg);
  15. background-size: cover;
  16. }
  17. figure img {
  18. position: absolute;
  19. top: 0;
  20. left: 0;
  21. width: 100%;
  22. transition: 2s ease-in-out;
  23. }
  24. figure img:first-of-type {
  25. clip-path: polygon(0 0, 100% 0, 100% 50%, 0 50%);
  26. }
  27. figure img:last-of-type {
  28. clip-path: polygon(0 50%, 100% 50%, 100% 100%, 0 100%);
  29. }
  30. figure:hover img:first-of-type {
  31. transform: translateY(-45%);
  32. }
  33. figure:hover img:last-of-type {
  34. transform: translateY(45%);
  35. }
  36. figcaption {
  37. position: absolute;
  38. top: 0;
  39. width: 100%;
  40. height: 100%;
  41. padding-top: 12vw;
  42. color: white;
  43. font-size: 10vw;
  44. text-align: center;
  45. }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

互联网寡头战争

互联网寡头战争

屈运栩 / 浙江大学出版社 / 2017-5-1 / CNY 49.00

本书意在复盘2015年下半年资本寒冬袭来之后,互联网行业发生的小巨头并购等连锁反应,揭示其背后推手——以BAT(百度、阿里巴巴、腾讯)为首的互联网巨头在零售、出行、本地生活、金融等行业的布局竞争,记录和呈现行业新贵的选择与博弈,深度剖析中国互联网生态的演进过程。一起来看看 《互联网寡头战争》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试