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

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

核心属性

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. }

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

查看所有标签

猜你喜欢:

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

Data Structures and Algorithms with JavaScript

Data Structures and Algorithms with JavaScript

Michael McMillan / O'Reilly Media / 2014-2-22 / USD 28.51

If you’re using JavaScript on the server-side, you need to implement classic data structures that conventional object-oriented programs (such as C# and Java) provide. This practical book shows you how......一起来看看 《Data Structures and Algorithms with JavaScript》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具