次にテキスト入力に通知を表示して、テキストが保存されたことをユーザーに通知し、その通知テキストをフェードアウトさせようとしています。
基本的に、対応するテキスト入力が送信されたときに、このアクションを複製しようとしています。
$(this).fadeOut().next().fadeIn();
フェードインしてからフェードアウトする方法は考えられません。
私も Redux を使用しており、それを使用したいと考えていますが、必須ではありません。アドバイスをいただければ幸いです。
次にテキスト入力に通知を表示して、テキストが保存されたことをユーザーに通知し、その通知テキストをフェードアウトさせようとしています。
基本的に、対応するテキスト入力が送信されたときに、このアクションを複製しようとしています。
$(this).fadeOut().next().fadeIn();
フェードインしてからフェードアウトする方法は考えられません。
私も Redux を使用しており、それを使用したいと考えていますが、必須ではありません。アドバイスをいただければ幸いです。
CSS を使用してそれを処理できます。これは非常に単純な例です (redux を使用していません)。JS を使用してトリガーし、CSS をスタイルに使用します。
class App extends React.Component {
constructor() {
super();
this.state = {
show: false
};
this.showNotification = this.showNotification.bind(this);
}
showNotification() {
// You can use redux for this.
this.setState({
show: true,
});
setTimeout(() => {
this.setState({
show: false,
});
}, 1000);
}
render() {
return (
<div>
<button onClick={this.showNotification}>Save</button>
<Notification show={this.state.show} />
</div>
);
}
}
class Notification extends React.Component {
render() {
return <span className={this.props.show ? 'show' : ''}>Saved!</span>
}
}
ReactDOM.render(<App/>, document.getElementById('View'));
span {
transition: 300ms all ease;
opacity: 0;
will-change: opacity;
}
.show {
opacity: 1;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="View"></div>