关键点
- CSS resize 属性允许你控制一个元素的可调整大小性
- 配合 resize 实现子元素的动态宽度
HTML:
1 2 3 4 5 | <div class= "picA" > <div class= "picB" > <div class= "resizeElement" ></div> </div> </div> |
SCSS:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | html { background : #ddd ; height : 100% ; width : 100% ; } .picA { 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 : 1 rem auto ; position : relative ; overflow : hidden ; } .picB { 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 5 s normal ease-in-out 1 s; } @keyframes delta { 30% { width : 0 ; } 60% { width : 350px ; } 100% { width : 0 ; } } |
效果如下:
到此这篇关于如何使用 resize 实现图片切换预览功能的文章就介绍到这了,更多相关resize 图片切换预览内容请搜索IT俱乐部以前的文章或继续浏览下面的相关文章,希望大家以后多多支持IT俱乐部!