【问题标题】:CSS transition not working in Styled ComponentCSS 过渡在样式化组件中不起作用
【发布时间】:2020-04-16 19:01:01
【问题描述】:

props.pop 发生变化时,我正在尝试缓慢(500 毫秒)扩展 Brandsdiv。 pop 将等于 truefalse。目前,transform: ${props => (props.pop ? "scale(1.2)" : "scale(1)")}; 工作正常并在pop = true 时缩放 div 但转换不起作用 - 缩放突然改变。

import React from 'react'
import styled from 'styled-components'

const LogoImg = styled.img`
  max-width: 100%;
  padding: 5px;
`

export default function FeaturedManufacturerLink(props) {
  const {
    brandPagePath, 
    logo, 
    pop
  } = props

  const Brandsdiv = styled.div`
    transition: transform 500ms;
    display: flex;
    width: 116px;
    height: 85px;
    border-radius: 50%;
    margin: 25px 35px;
    align-items: center;
    text-align: center;
    transform: ${props => (props.pop ? "scale(1.2)" : "scale(1)")};
  `
  return (
    <Brandsdiv pop={pop}>
      <a href={brandPagePath}>
        <LogoImg src={logo} />
      </a>
    </Brandsdiv>
  )
}

【问题讨论】:

    标签: css reactjs


    【解决方案1】:

    我移动了const Brandsdiv。 prop 更改 pop 导致组件重新渲染。

    【讨论】:

      猜你喜欢
      • 2019-11-16
      • 2021-08-22
      • 2019-04-21
      • 1970-01-01
      • 2015-12-01
      • 2012-09-27
      相关资源
      最近更新 更多