vue+animation实现翻页动画

前端在做数据展示的时候 可能提留页面时间较长 导致数据不能及时更新 你可以定时更新  也可以做一个假数据 给用户视觉上的体验  接下来就是第二种 假数据 它用了C3 animation 实现了一个翻页动画

第一种是单独运动

<template>
    <div>
        <div>
            <ul>
                <li v-for="(item,i) in NumberList" :key="i" ><a :class="[item.isMove ? 'move-an' : '']">{{item.num}}</a></li>
            </ul>
        </div>
    </div>
</template>
<script>
export default {
    data(){
        return {
            NumberList:'',
            Number:108847,
        }
    },
    mounted(){
        let arr = String(this.Number).split('')
        this.NumberList=[]
        arr.forEach(item => {
            const model = {};
            model.isMove = false;
            model.num = item;
            this.NumberList.push(model);
        });
        setInterval(() =>{
            this.Number=this.Number+1;
            let data = String(this.Number);
            let arr = data.split("");
            arr.forEach((item, index) => {
                if (item !== this.NumberList[index].num) {
                    this.NumberList[index].isMove = true
                }
            });
        }, 10000)
    },
    watch: {
        Number() {
            setTimeout(() =>{
                let data = String(this.Number);
                let arr = data.split("");
                this.NumberList.forEach((item, index) => {
                this.NumberList[index].num = arr[index];
                });
            }, 500);
            setTimeout(() =>{
                this.NumberList.forEach((item, index) => {
                this.NumberList[index].isMove = false
                });
            }, 1000);
        }
    },
    methods:{
    }
}
</script>
<style lang="" scoped>
    h1{
        text-align:center;
    }
    ul{
        display: flex;
        
    }
    li{
        list-style: none;
        width:50px;height:80px;
        background: red;
        margin-right: 10px;
        text-align: center;
        line-height: 80px;
        font-size:20px;
        color:#ffffff;
        position: relative;
    }
    a {
        position: absolute;
        top: 3px;
        color: #ffffff;
    }
    .move-an {
        animation:mymove 1s infinite linear;
        -webkit-animation:mymove 1s infinite linear;
    }
    @keyframes mymove {
    0%   {top: 3px;}
    25%  {top: -40px;}
    48%  {top: -80px;}
    49%  {top: -80px; opacity: 0}
    50%  {top: 80px;}
    51%  {top: 80px;opacity: 1; }
    100% {top: 3px;}
    }
</style>

第二种是整体运动 0-9循环一边

<template>
    <div class="main">
        <div v-for="(item,i) in NumberList" class="move-num" :key="i">
            <div>
                <div style="visibility:hidden;position: static">
                    <span v-for="(list, i) in item.num" :key="i" class="num-move">{{list}}</span>
                </div>
                <a :class="[isMove === true ? 'move-an' : '']">
                    <span v-for="(list, i) in item.num" :key="i" class="num-move">{{list}}</span>
                </a>
            </div>
        </div>
    </div>
</template>
<script>
export default {
    data(){
        return {
            isMove:false,
            NumberList:[],
            Number:108847,
            numModels: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
        }
    },
    mounted(){
        this.handdleDate()
        setInterval(() => {
            this.handdleDate()
        }, 10000)
    },
    methods:{
        handdleDate(){
            let arr = String(this.Number).split('')
            this.NumberList=[]
            arr.forEach(item => {
                
                const model = {}
                const baseArr = JSON.parse(JSON.stringify(this.numModels))
                model.isMove = false;
                for (let i = 0; i < parseInt(item) + 1; i++) {
                    baseArr.push(i)
                }
                model.num = baseArr;
                this.NumberList.push(model);
                this.isMove = true;
                 setTimeout(() => {
                    this.isMove = false
                }, 3000)
            });
        }
    }
}
</script>
<style lang="" scoped>
.main{
    display: flex;
}
.move-num{
    width:30px;height:40px;
    background:red;
    overflow: hidden;
    margin-right:10px;
    line-height: 40px;
    color:#fff;
    position: relative;
    overflow: hidden;
}
.move-num div {
    position: absolute;
    width: 100%;
    height: auto;
    
  }
.move-num div a {
      color: #ffffff;
      display: block;
      position: absolute;
      left: 10px;
      bottom: calc(100% - 45px);
}
.num-move {
  width: 100%;
  display: block;
  margin: 3px  0;
}
.move-an {
    animation:mymove 3s infinite linear forwards;
    -webkit-animation:mymove 3s infinite linear forwards;
}
.num-move {
    width: 100%;
    display: block;
    margin: 3px  0;
}
@keyframes mymove {
    0%   {bottom: 3px;}
    100% {bottom: calc(100% - 40px)}
}
</style>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Vue Ant Design是一个基于Vue.js的UI组件库,可以帮助开发者快速构建漂亮且功能强大的前端界面。Vue Ant Design提供了丰富的组件和模板,方便开发者进行页面的构建和设计。 要实现模版下载,首先需要在项目中引入Vue Ant Design相关的依赖。可以通过npm或yarn安装Vue Ant Design并导入相关组件: ``` npm install ant-design-vue ``` 或者 ``` yarn add ant-design-vue ``` 然后,在主组件中导入需要的组件,并在Vue实例中注册它们: ```javascript <template> <div> <a-button type="primary" @click="downloadTemplate">下载模板</a-button> </div> </template> <script> import { Button } from 'ant-design-vue'; export default { components: { 'a-button': Button }, methods: { downloadTemplate() { // 实现模版下载的逻辑 } } } </script> ``` 在上述的示例中,通过引入Button组件,我们在模版中添加了一个按钮,点击按钮时会触发`downloadTemplate`方法。只需要在该方法中实现模版下载的逻辑即可。 模版下载的具体逻辑可以根据实际需求来设计,例如可以使用axios库向服务器发送HTTP请求,获取模版文件,并通过浏览器的下载功能将文件提供给用户下载。 在实现模版下载的逻辑时,还可以参考Vue Ant Design提供的其他组件和功能,例如Modal组件可以用来显示下载进度或下载成功的提示信息。 总之,通过结合Vue Ant Design提供的组件和功能,我们可以轻松地实现模版下载功能,从而提升开发效率。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

沫熙瑾年

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值