我有一个组件PromptBox
,我希望在从中心更改状态时在屏幕左侧显示动画。然后在另一个状态变化,从右侧,到中心动画
这是我的组件代码。我试图使用this.isActive()
函数来管理状态和动画,这只会使组件消失。
的 CSS:
.prompt-box {
display: block;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #1E1E1E;
width: 35%;
-webkit-transition-property: left;
-webkit-transition-duration: 1.0;
-webkit-transition-property: ease-in-out;
}
// before animating in (off to the right)
.prompt-box.ready {
left: 100%;
}
// animating out to the left
.prompt-box.done {
left: -100%;
}
JS:
isActive() {
const { activity } = this.state;
if (activity === 'done') {
return 'prompt-box done';
} else if (activity === 'ready') {
return 'prompt-box ready';
} else {
return 'prompt-box';
}
}
render() {
return (
<div className={this.isActive()}>
<p className='title'>What's in your future?</p>
<ul className='options-holder'>
{
this.state.items.map((item, index) => (
<li key={item.id} className={`option ${index === 0 ? 'first' : ''}`}>
<div className='circle' onClick={this.removeItem} />
<p className='item-text'>{ item.text }</p>
</li>
))
}
<li key={0} className={`option form ${this.state.items.length === 0 ? 'only' : ''}`} ref={el => (this.formLi = el)}>
<div className='circle form' />
<form className='new-item-form' onSubmit={this.handleSubmit}>
<input
autoFocus
className='new-item-input'
placeholder='Type something and press return...'
onChange={this.handleChange}
value={this.state.text}
ref={input => (this.formInput = input)} />
</form>
</li>
</ul>
<button className='confirm-button' onClick={this.submitAndContinue}>Continue</button>
</div>
);
}
答案 0 :(得分:1)
所以请将您的CSS更新为:
...
-webkit-transition-property: left;
-webkit-transition-duration: 1s;
-webkit-transition-timing-function: ease-in-out;