React学习笔记(7)---动画效果实现
2015-08-30 00:37
801 查看
1. 网页动画
在react中使用CSS3动画效果:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="build/react-with-addons.js"></script>
<script src="build/JSXTransformer.js"></script>
<style>
.example-enter{
opacity: 0.01;
transition: opacity.5s ease-in;
}
.example-enter.example-enter-active{
opacity: 1;
}
.example-leave{
opacity: 1;
transition: opacity.5s ease-in;
}
.example-leave.example-leave-active{
opacity: 0.01;
}
</style>
</head>
<body>
<script type="text/jsx">
var ReactCSSTransitionGroup = React.addons.CSSTransitionGroup;
var TodoList = React.createClass({
getInitialState: function () {
return {
items: ['hello','world','click','me']
};
},
handleAdd: function () {
var newItems = this.state.items.concat([prompt('Enter some text')]);
this.setState({items:newItems});
},
handleRemove: function (i) {
var newItems = this.state.items;
newItems.splice(i,1);
this.setState({items:newItems});
},
render: function () {
var items = this.state.items.map(function (item,i) {
return(
<div key={item} onClick={this.handleRemove.bind(this,i)}>
{item}
</div>
);
}.bind(this));
return (
<div>
<button onClick={this.handleAdd}>Add Item</button>
<ReactCSSTransitionGroup transitionName="example">
{items}
</ReactCSSTransitionGroup>
</div>
)
},
});
React.render(
<TodoList></TodoList>, document.body);
</script>
</body>
</html>
在react中使用CSS3动画效果:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="build/react-with-addons.js"></script>
<script src="build/JSXTransformer.js"></script>
<style>
.example-enter{
opacity: 0.01;
transition: opacity.5s ease-in;
}
.example-enter.example-enter-active{
opacity: 1;
}
.example-leave{
opacity: 1;
transition: opacity.5s ease-in;
}
.example-leave.example-leave-active{
opacity: 0.01;
}
</style>
</head>
<body>
<script type="text/jsx">
var ReactCSSTransitionGroup = React.addons.CSSTransitionGroup;
var TodoList = React.createClass({
getInitialState: function () {
return {
items: ['hello','world','click','me']
};
},
handleAdd: function () {
var newItems = this.state.items.concat([prompt('Enter some text')]);
this.setState({items:newItems});
},
handleRemove: function (i) {
var newItems = this.state.items;
newItems.splice(i,1);
this.setState({items:newItems});
},
render: function () {
var items = this.state.items.map(function (item,i) {
return(
<div key={item} onClick={this.handleRemove.bind(this,i)}>
{item}
</div>
);
}.bind(this));
return (
<div>
<button onClick={this.handleAdd}>Add Item</button>
<ReactCSSTransitionGroup transitionName="example">
{items}
</ReactCSSTransitionGroup>
</div>
)
},
});
React.render(
<TodoList></TodoList>, document.body);
</script>
</body>
</html>
相关文章推荐
- React学习笔记(6)---组件协同使用介绍
- ReactiveCocoa信号使用方法
- React学习笔记(5)--事件
- React 实践记录 02 Flux introduction
- React组件开发入门
- Facebook React Native 中文教程一:介绍
- ReactiveCocoa Documents 翻译(基于版本V2.5)
- java设计模式-reactor模式
- React 实践记录 01 组件开发入门
- ReactiveCocoa2 源码浅析
- [React] React Fundamentals: Precompile JSX
- React学习笔记(4)---react属性与状态
- React学习笔记(3)-- JSX语法及特点介绍
- react学习笔记(2)---组件的生命周期
- Reactivecocoa-publish、multicast、replay、replayLast
- react-native试玩(4)-新建项目
- React Native常用组件
- React学习笔记(1)--第一个程序
- [React] React Fundamentals: JSX Deep Dive
- [React] React Fundamentals: Build a JSX Live Compiler