zoukankan      html  css  js  c++  java
  • 自写组件集合

    1.ToolTip

    import {useState,useRef} from 'react';
    
    
    const ToolTip  = (props) => {
        const TxtRef = useRef();
        const TimeoutRef = useRef()
        const style = {
            bottom:{
                position:'absolute',
                left:TxtRef.current && TxtRef.current.clientWidth,
                top:TxtRef.current && TxtRef.current.clientHeight,
                padding:'3px 6px',
                backgroundColor:'rgba(238, 239, 239,.6)',
                boxShadow:'0 0 2px #ccc',
                whiteSpace:'nowrap',
                fontSize:12,
                color:'#333'
            }
        };
        const [bottom,setBottom] = useState(false)
        return (
            <div style={{position:"relative",cursor:"pointer"}}
                 onMouseEnter={()=>{
                     TimeoutRef.current = setTimeout(()=>{
                         setBottom(true)
                     },1000)
                 }}
                 onMouseLeave={()=>{
                     console.log('让我康康',TxtRef.current.clientWidth);
                     setBottom(false)
                     clearTimeout(TimeoutRef.current)
                 }}
            >
                <div
    
                    style={bottom?{...style.bottom}:{display:'none'}}
                >
                    {props.txt}
                </div>
                <div style={{...props.style}}
                     ref={TxtRef}
                >
                    {props.txt}
                </div>
            </div>
        )
    };
    
    export default ToolTip
    ToolTip.js
  • 相关阅读:
    解释器模式
    命令模式
    责任链模式
    代理模式
    享元模式
    外观模式
    装饰器模式
    组合模式
    过滤器模式
    js广告浮动
  • 原文地址:https://www.cnblogs.com/it-Ren/p/13458286.html
Copyright © 2011-2022 走看看