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>


在Vue中,router-link是用来生成导航链接的组件,它最后会被转换成a标签。要实现router-link的过渡效果,可以使用Vue的过渡动画实现。首先,在router-link上添加一个transition标签,并设置name属性为"fade",然后在<style>标签中定义.fade-enter-active、.fade-leave-active和.fade-enter类名的过渡效果,如下所示: ```html <transition name="fade"> <router-link to="/myInfo">新页面打开myInfo页</router-link> </transition> <style> .fade-enter-active, .fade-leave-active { transition: opacity 0.5s; } .fade-enter, .fade-leave-to { opacity: 0; } </style> ``` 这样就可以给router-link添加过渡效果了。在这个例子中,定义了一个名为fade的过渡动画,当router-link进入或离开时,会通过opacity属性来实现淡入淡出的效果。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Vue学习笔记(六)--- 前端路由 Vue Router](https://blog.csdn.net/weixin_45092437/article/details/120842075)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [react-router-dom 简明教程](https://blog.csdn.net/IT_bar/article/details/117002395)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值