首页代码教程CSS纯干货:如何使用 resize 实现图片切换预览功能

纯干货:如何使用 resize 实现图片切换预览功能

3年前 (2024-03-10)CSS3.1k

复制本页网址打印

关键点

  • CSS resize 属性允许你控制一个元素的可调整大小性
  • 配合 resize 实现子元素的动态宽度

HTML:
 

  <div class='picA'>      <div class='picB'>          <div readonly class='resizeElement'></div>      </div>  </div>

SCSS:

  html {      background: #ddd;      height: 100%;      width: 100%;  }  .picA {      background-image: url(https://z3.ax1x.com/2021/08/17/fhJdpQ.png);      background-size: cover;      width: 650px;      height: 340px;      border: 5px solid #f0e5ab;      border-radius: 3px;      box-shadow: 0 0 1px #999, -2px 2px 3px rgba(0, 0, 0, 0.2);      padding: 0;      margin: 1rem auto;      position: relative;      overflow: hidden;  }  .picB {      background-image: url(https://z3.ax1x.com/2021/08/17/fhJUfg.png);      background-size: cover;      height: 340px;      position: absolute;      top: 0;      left: 0;      min-width: 0;      max-width: 650px;      box-sizing: border-box;  }  .picB:before {      content: "↔";      position: absolute;      background: rgba(0, 0, 0, 0.5);      font-size: 16px;      color: white;      top: 0;      right: 0;      height: 100%;      line-height: 340px;  }  .resizeElement {      resize: horizontal;      overflow: scroll;      opacity: 0;      position: relative;      top: 50%;      left: 0px;      height: 15px;      max-width: 650px;      min-width: 15px;      width: 0;      cursor: move;      transform: scaleY(35);      transform-origin: center center;      animation: delta 5s normal ease-in-out 1s;  }  @keyframes delta {      30% {          width: 0;      }      60% {          width: 350px;      }      100% {          width: 0;      }  }

效果如下:

益吾库今天分享的这篇关于纯干货:如何使用 resize 实现图片切换预览功能的内容到这里就结束了,喜欢的话可以给我们点赞鼓励~

0
打赏

重要声明
当前栏目内容除非特别标注,否则均来源于网络公开信息整理分享,本站不提供存储和下载服务,且无法保证第三方链接永久可靠。您若对本站或当前页面内容有疑问或者建议,欢迎联系我们,我们将尽快处理,谢谢支持!