zoukankan      html  css  js  c++  java
  • 可拖拽布局组件

    import React from 'react';
    import style from './index.module.scss';
    
    const icon = `<svg t="1587390375993" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="893" width="200" height="200"><path d="M912 512c0 7.7-2.8 14.5-8.5 20.1L789.3 646.5c-5.6 5.6-12.4 8.5-20.1 8.5-7.7 0-14.5-2.8-20.1-8.5-5.6-5.6-8.5-12.3-8.5-20.1v-57.2H283.5v57.2c0 7.7-2.8 14.5-8.5 20.1-5.6 5.6-12.4 8.5-20.1 8.5-7.7 0-14.5-2.8-20.1-8.5L120.5 532c-5.6-5.6-8.5-12.3-8.5-20.1 0-7.7 2.8-14.5 8.5-20.1l114.3-114.3c5.6-5.6 12.3-8.5 20.1-8.5 7.7 0 14.5 2.8 20.1 8.5 5.6 5.6 8.5 12.4 8.5 20.1v57.2h457.2v-57.2c0-7.7 2.8-14.5 8.5-20.1 5.6-5.6 12.3-8.5 20.1-8.5 7.7 0 14.5 2.8 20.1 8.5l114.4 114.3c5.4 5.7 8.2 12.5 8.2 20.2z" p-id="894"></path></svg>`;
    
    export default (props: {
    
        /**  初始左侧宽度 */
        initLeftConnWidth?: number;
    
        /** 左侧显示对象 */
        liftChild: React.ReactChild;
    
        /** 右侧显示对象 */
        rightChild: React.ReactChild;
    }) => {
    
        const [leftConnWidth, setLeftConnWidth] = React.useState(props.initLeftConnWidth || 200)
    
        const onMouseDownAdjust = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
    
            const oldScreenX = e.screenX;
            const oldWidth = leftConnWidth;
            const mask = document.createElement('div');
            mask.className = style.shelfMask;
            
            window.top.document.body.appendChild(mask);
    
            mask.addEventListener('mousemove', onmousemove);
            mask.addEventListener('mouseup', onmouseup);
    
            /** 移动鼠标 */
            function onmousemove(e1) {
                let newWidth = oldWidth + (e1.screenX - oldScreenX);
                if (newWidth < 0) {
                    newWidth = 0;
                }
                if (newWidth > 1000) {
                    newWidth = 1000;
                }
                setLeftConnWidth(newWidth);
            }
    
            function onmouseup() {
                mask.removeEventListener('mousemove', onmousemove);
                mask.removeEventListener('mouseup', onmouseup);
                window.top.document.body.removeChild(mask);
            }
        }
    
        return (
            <div className={style.shelf} >
                <div className={style.leftConn} style={{  leftConnWidth }} >
                    {props.liftChild}
                </div>
                <i className={style.adjust} dangerouslySetInnerHTML={{ __html: icon }} onMouseDown={onMouseDownAdjust} ></i>
                <div className={style.rightConn} >
                    {props.rightChild}
                </div>
            </div>
        )
    }
    

      

  • 相关阅读:
    《鸟哥的私房菜阅读摘要》——linux的简介和计算机基础
    抽象类可以有构造函数吗
    Java对象及对象引用变量
    html5的学习笔记
    xhtml的学习笔记
    交换机配置原理
    (转)MSI
    python xy
    Microsoft SilverLightt是一个跨浏览器的、跨平台的插件,为网络带来下一代基于.NETFramework的媒体体验和丰富的交互式应用程序。
    epub使用Adobe Digital Editions打开
  • 原文地址:https://www.cnblogs.com/zhaoyzml/p/14312343.html
Copyright © 2011-2022 走看看