效果
具体实现
template
< Panel class = "detail-drawer" >
< div class = "panel-handle"
@mousedown= "stretchPanel"
@mouseup= "stopStretch>
< / div>
< / Panel>
script
let panelParams = reactive ( {
panel : null ,
clientX : 0 ,
width : 0 ,
minWidth : 0 ,
} )
const mouseMoveHandler = ( e ) => {
let moveX = panelParams. clientX - e. clientX
let newWidth = panelParams. width + moveX
if ( newWidth > panelParams. minWidth) {
panelParams. panel. style. width = newWidth + 'px'
} else {
panelParams. panel. style. width = panelParams. minWidth + 'px'
}
}
const stretchPanel = ( e ) => {
let element = document. querySelector ( '.flowchat-container' )
let panel = document. querySelector ( '.detail-drawer' )
panelParams. panel = panel
panelParams. clientX = e. clientX
panelParams. width = panel. clientWidth
panelParams. minWidth = element. clientWidth * 0.32
document. addEventListener ( 'mousemove' , mouseMoveHandler)
document. addEventListener ( 'mouseup' , stopStretch)
}
const stopStretch = ( ) => {
document. removeEventListener ( 'mousemove' , mouseMoveHandler)
document. removeEventListener ( 'mouseup' , stopStretch)
}
style
:主要就是定义panel-handle
相对父级detail-drawer
的高度和位置,我定义的handle在左边框,实现左右伸缩。
cursor: ew-resize
:定义伸缩图标cursor:move
:定义拖拽十字图标cursor:pointer
:定义手型图标cursor
:更多样式参考
. detail- drawer {
position : absolute;
right : 10px;
top : 3 % ;
width : 32 % ;
height : 93 % ;
background : #ffffff;
border- radius: 12px;
box- shadow: 0px 0px 1px 0px rgba ( 19 , 51 , 107 , 0.08 ) , 0px 1px 2px 0px rgba ( 19 , 51 , 107 , 0.05 ) ;
border : 1px solid #dfe2ea;
margin : 0 ;
padding : 10px;
. panel- handle {
position : absolute;
left : - 3px;
width : 6px;
height : 98 % ;
cursor : ew- resize;
}
}