var Hello = React.createClass({
getInitialState: function() {
return {
gridIsLoaded: true
}
},
animate(self) {
console.log('animating...');
$('#loadingDiv').animate({'opacity': '0'}, 500, function(){
$('#loadingDiv').animate({'opacity': '.5'}, 500, function(){
$('#loadingDiv').animate({'opacity': '1'}, 500, function(){
//if(!self.state.gridIsLoaded){
self.animate();
//}
});
});
});
},
getData() {
console.log('getData called.');
var artificialTimeout = 5000;
var self = this;
self.animate(self);
$.ajax({
url:'/echo/js/?js=hello%20world!',
complete: function (response) {
console.log(response.responseText);
setTimeout(function() {
self.setState({gridIsLoaded: true});
}, artificialTimeout);
},
error: function() {
console.log('there was an error!');
self.setState({gridIsLoaded: true});
},
});
return false;
},
handleClick(){
console.log('handleClick');
this.getData();
this.setState({gridIsLoaded: false});
},
render: function() {
var loadingJsx;
if (!this.state.gridIsLoaded) {
loadingJsx = (
<div id="loadingDiv" style={{ position:'relative', 'width': '100%', 'textAlign': 'center'}} className="text-center">
Loading... please wait
</div>);
};
return <div>
{loadingJsx}
<div>
<input type="button" value="Submit" onClick={this.handleClick} />
</div>
</div>;
}
});
ReactDOM.render(
<Hello name="World" />,
document.getElementById('container')
);
を反応させる働きのローディングアニメーションを作成します。私は、読み込み中に不透明度をアニメーションで出し入れする必要があります。それは動作していません。それから、もう一度submitをクリックすると同じことが起こります。
アニメーションを機能させるにはどうすればよいですか?
Simple case外部からの反応があります。
あなたは、CSSを追加したり、あなたが純粋なJSを好むだろうと大丈夫ですか?どちらかといえば大丈夫ですが、反応スタイルをjquery/dom操作スタイルと混ぜ合わせるときにアプローチを変更する必要があるでしょう。これは一般的にぼやけています。 – aw04
@ aw04 - うまくいく方法はありません。 –