【发布时间】:2019-03-27 20:22:04
【问题描述】:
所以我的功能是:
function onClickChange(props) {
let MyDiv = document.getElementById('myDIV')
let InterfaceDesign = document.getElementById('interfaceDesign')
if (MyDiv.style.display === 'none') {
MyDiv.style.display = ''
InterfaceDesign.classList.add('active')
} else {
MyDiv.style.display = 'none'
InterfaceDesign.classList.remove('active')
}
}
从 DOM 中的这个函数我可以看到它正在获取活动类。但是从我的样式组件中:
const FirstDivElement = styled.div`
position: relative;
overflow: hidden;
width: 100%;
background-color: #000;
&:hover {
background-color: #e6007e;
transform: scale(1.05);
}
&:active{
background-color: #e6007e;
}
`
它没有得到 &:active 的样式
我的 div 元素是:
<div id="interfaceDesign">
<div onClick={onClickChange}>
<ListItems
headingText="Interface Design"
backgroundImage={props.secondBackgroundImage}
>
<Img
style={{
height: '50px',
width: '50px',
}}
sizes={props.interfacedesign}
/>
</ListItems>
</div>
</div>
<div id="myDIV" style={{ display: 'none' }}>
<InterfaceDesign
secondBackgroundImage={props.secondBackgroundImage}
interfacedesignMagenta={props.interfacedesignMagenta}
/>
</div>
</div>
有人可以帮忙吗?提前谢谢你:D
【问题讨论】:
-
与您的问题无关,但您应该注意,使用 DOM 作为您的状态的源是违反 React 的工作方式(状态从父级流向子级,并且 DOM 由 React 处理)。
标签: javascript css reactjs styled-components gatsby