实现鼠标长按某一区域可上下改变盒子高度大小

组件

import {ResizeSensor} from 'css-element-queries';

function ContainerFoot(props) {
    const {isCover, onPosition} = props;
    const [max, setMax] = useState(600);
    const {position, separatorProps} = useResizable({axis: 'y', initial: 312, min: 208, max, reverse: true});

    useEffect(() => {
        const el = document.querySelector(`.${style.container}`);
        const resizeSensor = new ResizeSensor(el, size => {
            setMax(size.height - 240);
        });
        return () => resizeSensor?.detach();
    }, []);

    useEffect(() => {
        // onPosition(position);
    }, [position]);

    return (
        <div className={style.container_foot} style={
  
  {height: position}}>
            <div className={style.container_foot_separator} {...separatorProps}></div>
            {isCover ? <ContainerFootDisableCover /> : <ContainerFootContent />}
        </div>
    );
}


样式

.container_foot_separator {
    width: 100%;
    height: 4px;
    background: #191924;
    cursor: row-resize;
}


.container_foot {
    flex: none;
    background: #2b2e3e;
    height: 312px;
    // margin-top: 4px;
    position: relative;
}

js

import {useCallback, useRef, useState} from 'react';

const KEYS_LEFT = ['ArrowLeft', 'Left'];
const KEYS_RIGHT = ['ArrowRight', 'Right'];
const KEYS_UP = ['ArrowUp', 'Up'];
const KEYS_DOWN = ['ArrowDown', 'Down'];
const KEYS_AXIS_X = [...KEYS_LEFT, ...KEYS_RIGHT];
const KEYS_AXIS_Y = [...KEYS_UP, ...KEYS_DOWN];
const KEYS_POSITIVE = [...KEYS_RIGHT, ...KEYS_DOWN];

const useResiz
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值