经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » HTML/CSS » CSS » 查看文章
如何使用 resize 实现图片切换预览功能_CSS教程_CSS
来源:jb51  时间:2021/8/26 8:55:06  对本文有异议

关键点

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

HTML:
 

  1. <div class='picA'>
  2. <div class='picB'>
  3. <div readonly class='resizeElement'></div>
  4. </div>
  5. </div>

SCSS:

  1. html {
  2. background: #ddd;
  3. height: 100%;
  4. width: 100%;
  5. }
  6. .picA {
  7. background-image: url(https://z3.ax1x.com/2021/08/17/fhJdpQ.png);
  8. background-size: cover;
  9. width: 650px;
  10. height: 340px;
  11. border: 5px solid #f0e5ab;
  12. border-radius: 3px;
  13. box-shadow: 0 0 1px #999, -2px 2px 3px rgba(0, 0, 0, 0.2);
  14. padding: 0;
  15. margin: 1rem auto;
  16. position: relative;
  17. overflow: hidden;
  18. }
  19. .picB {
  20. background-image: url(https://z3.ax1x.com/2021/08/17/fhJUfg.png);
  21. background-size: cover;
  22. height: 340px;
  23. position: absolute;
  24. top: 0;
  25. left: 0;
  26. min-width: 0;
  27. max-width: 650px;
  28. box-sizing: border-box;
  29. }
  30. .picB:before {
  31. content: "↔";
  32. position: absolute;
  33. background: rgba(0, 0, 0, 0.5);
  34. font-size: 16px;
  35. color: white;
  36. top: 0;
  37. right: 0;
  38. height: 100%;
  39. line-height: 340px;
  40. }
  41. .resizeElement {
  42. resize: horizontal;
  43. overflow: scroll;
  44. opacity: 0;
  45. position: relative;
  46. top: 50%;
  47. left: 0px;
  48. height: 15px;
  49. max-width: 650px;
  50. min-width: 15px;
  51. width: 0;
  52. cursor: move;
  53. transform: scaleY(35);
  54. transform-origin: center center;
  55. animation: delta 5s normal ease-in-out 1s;
  56. }
  57. @keyframes delta {
  58. 30% {
  59. width: 0;
  60. }
  61. 60% {
  62. width: 350px;
  63. }
  64. 100% {
  65. width: 0;
  66. }
  67. }

效果如下:

到此这篇关于如何使用 resize 实现图片切换预览功能的文章就介绍到这了,更多相关resize 图片切换预览内容请搜索w3xue以前的文章或继续浏览下面的相关文章,希望大家以后多多支持w3xue!

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号