antd的Tooltip组件添加动画效果之后,延迟消失

需求

给“插入”按钮添加tooltip,并且当鼠标移动到“插入”按钮时,让tooltip消失
在这里插入图片描述

bug描述和源码

这个tooltip在添加了css上下移动的动画之后,鼠标滑出本来tooltip应该立刻消失的,但是它延迟了1s左右,才消失

代码展示:

 .introduce-insert {
     animation: move-down-up ease-in-out 1s infinite;
 }



  // 一上一下动画效果
  @keyframes move-down-up {
    0% {
      transform: translateY(0);
    }
    50% {
      transform: translateY(6px);
    }
    100% {
      transform: translateY(0);
    }
  }

  const [hoverInsertMain, setHoverInsertMain] = useLocalStorageState('show-insertmain-instruction', {
    defaultValue: true,
  }) // 控制“插入”功能引导popover的显示和隐藏
  
  {/* 新增“插入”菜单项 */}
          <Popover
            // open={visibleMore}
            trigger="hover"
            overlayClassName="insert-main-popover"
            getPopupContainer={node => node}
            content={
              <MoreBtnStyle>
                <div
                  className="moreBtn"
                  onClick={event => {
                    // setVisibleMore(false)
                    event.stopPropagation()
                  }}
                >
                  {toolbar.mainInsertMenu.map((item, index) => {
                    return (
                      <Fragment key={index}>
                        正常的tooltip
                      </Fragment>
                    )
                  })}
                </div>
              </MoreBtnStyle>
            }
          >
            <Popover
              open={hoverInsertMain}
              getPopupContainer={node => node}
              overlayClassName="introduce-insert"
              zIndex={1}
              content={
                <div className="introduce-text">
                 这时添加了动画的tooltip
                </div>
              }
            >
              <div
                style={{ color: !isLook && isSelectNode ? '#323233' : '', cursor: 'pointer' }}
                onClick={event => {
                  event.stopPropagation()
                  setHoverInsertMain(false)
                }}
                onMouseEnter={() => {
                  setHoverInsertMain(false)
                }}
              >
                <SvgIcon
                  iconName="charu"
                  type="park"
                  className={`topIcon ${!isLook && isSelectNode ? 'active' : ''}`}
                ></SvgIcon>
                插入
              </div>
            </Popover>
          </Popover>

原因和解决方法

因为antd的Tooltip的消失本身是有一个动画的(在1s内逐渐变小),所以我添加的动画和官方的冲突了,就会继续上下移动的动画1s才消失。

改进如下:

在需要添加动画的Tooltip组件里面加上:

    overlayStyle={{ animation: hoverInsertMain ? 'move-down-up ease-in-out 1s infinite' : undefined }}

这样当需要Tooltip消失的时候,也就是hoverInsertMain是false时,我新添加的动画消失,tooltip继续执行它消失的动画。就不会有一个1s的延迟了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值