谷歌浏览器上带有黑线的最大高度动画

时间:2020-05-01 05:16:38

标签: css reactjs

您好,由于某些原因,我的下拉菜单左栏存在以下问题(仅适用于Chrome):

关于gif的问题:

enter image description here

但是在firefox上正常工作就像这样gif,并且没有黑线:

enter image description here

我使用react + emotion js,但这是CSS的问题

我的jsx代码:

const Drop = ({ active, isOpen, dropItems, setVisible, Icon }) => {
  return (
    <OpenedStyled active={active}>
      {dropItems.map(item => (
        <li className="li-open" key={item.Name}>
          <Icon />
          <a>{item.Name}</a>
        </li>
      ))}
    </OpenedStyled>
  );
};
const MenuTags = () => {
  const [menuItems, setMenuItems] = useState(SideBarTags);
  const showHideDropItem = tag => {
    setMenuItems(items =>
      items.map(item => ({
        ...item,
        Active:
          item.Name === tag.Name ? (tag.Active === true ? false : true) : false
      }))
    );
  };
  const clickHandler = tag => () => {
    showHideDropItem(tag);
  };
  return (
    <DashMenu>
      <MenuList>
        {menuItems.map((item, index) => (
          <ListItem>
            <ListWrap
              onClick={
                item.Active !== undefined
                  ? clickHandler(item)
                  : () => {
                      // foo is safely hidden within initialize, but...
                      console.log("a", item);
                    }
              }
            >
              <a>
                <item.Icon size={18} />
                <span className="li-name">{item.Name}</span>
              </a>
            </ListWrap>
            {item.DropdownItems ? (
              <Drop
                active={item.Active}
                dropItems={item.DropdownItems}
                Icon={item.Icon}
                setVisible={clickHandler}
              />
            ) : (
              ""
            )}
          </ListItem>
        ))}
      </MenuList>
    </DashMenu>
  );
};

我的CSS代码:

export const DashMenu = styled.div`
  display: flex;
  flex-direction: column;
`;
export const MenuList = styled.ul`
  font-family: "Ubuntu";
  font-size: 14px;
  font-weight: 300;
  text-decoration: none;
  color: #fff;
  padding-top: 10px;
`;

export const ListItem = styled("li")`
  display: flex;
  flex-direction: column;
  position: relative;
  justify-content: space-between;
  cursor: pointer;
`;

export const ListWrap = styled.div`
  padding: 12px 20px 12px 20px;
  display: flex;
  transition: background 1s;
  justify-content: space-between;
  ${props => {
    if (props.active) {
      return css`
        border-left: 3px solid orange;
        background: ${shade(0.4, "#3c8dbc")};
        :hover,
        :active {
          background: ${shade(0.4, "#3c8dbc")};
        }
        -webkit-transition: all 0.5s;
        -moz-transition: all 0.5s;
        -ms-transition: all 0.5s;
        -o-transition: all 0.5s;
        transition: all 0.5s;
      `;
    }
  }}
  a {
    display: flex;
    align-items: center;
    svg {
      margin-right: 10px;
    }
  }
  & .icon-li {
    margin-right: 10px;
  }
  & .down-up_svg,
  .li-name {
    display: space-between;
  }
`;

export const OpenedStyled = styled.ul`
  ${props => {
    if (props.active) {
      return css`
        max-height: 400px !important;
      `;
    }
  }}
  max-height: 0;
  overflow: hidden;
  padding: 0;
  background: #307096;
  -webkit-transition: max-height 0.5s;
  -moz-transition: max-height 0.5s;
  -ms-transition: max-height 0.5s;
  -o-transition: max-height 0.5s;
  transition: max-height 0.5s;
  li {
    white-space: nowrap;
    padding: 7px 15px;
  }
  a {
    font-family: "Ubuntu";
    font-size: 14px;
    font-weight: 300;
    text-decoration: none;
    color: #fff;
  }
  & .li-open:hover > .icon-li-drop {
    color: orange;
    transition: color 1s;
  }
  & .icon-li-drop {
    margin-right: 10px;
  }
`;

在OpenedStyled组件上,我具有动画下拉菜单maxheight

示例工作:

https://codesandbox.io/s/keen-stonebraker-pmmxd?file=/src/styled.js:3996-4008

0 个答案:

没有答案