React学习笔记(7)---动画效果实现

前端之家收集整理的这篇文章主要介绍了React学习笔记(7)---动画效果实现前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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>
原文链接:https://www.f2er.com/react/307794.html

猜你在找的React相关文章