vue中的数字滚动和翻牌器

 更新时间:2023年10月21日 09:59:07   作者:小矮马  
这篇文章主要介绍了vue中的数字滚动和翻牌器,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教

1、数字滚动vue-count-to

(1)安装:

npm install vue-count-to

(2)使用:

<template>
    <div>
        <h2>数字滚动动画:</h2>
        <CountTo :start-val="startVal" :end-val="endVal" :duration="2500" class="count-number"></CountTo>
    </div>
</template>
 
<script>
    import CountTo from 'vue-count-to'
    export default {
        components: {
            CountTo
        },
        data() {
            return {
                startVal: 0,
                endVal: 2017
            }
        }
</script>

(3)说明:

参考链接:http://panjiachen.github.io/countTo/demo/

2、翻牌器组件

(1)组件:

<template>
    <div class="count-flop" :key="compKey">
        <div :class="item!='.'?'count-flop-box':'count-flop-point'" v-for="(item, index) in value" :key="index">
            <div v-if="item!='.'" class="count-flop-content" :class="['rolling_' + item]">
                <div v-for="(item2,index2) in numberList" :key="index2" class="count-flop-num">{{item2}}</div>
            </div>
            <div v-else class="count-flop-content">.</div>
        </div>
        <div v-if="suffix" class="count-flop-unit">{{suffix}}</div>
    </div>
</template>
<script>
    export default {
        data() {
            return {
                value: [],
                numberList: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
                compKey: 0
            };
        },
        props: ["val","suffix"],
        watch: {
            val() {
                this.value = this.val.toString().split("");
                this.compKey += 1;
            }
        },
        created() {
            this.value = this.val.toString().split("");
        },
    };
</script>
<style scoped>
    .count-flop {
        display: inline-block;
        font-size: 0;
        /* 可更改 */
        height: 50px;
        line-height: 50px;
        font-size: 36px;
        color: #4898f1;
    }
 
    .count-flop > div {
        position: relative;
        display: inline-block;
        overflow: hidden;
        height: 100%;
    }
 
    .count-flop-box {
        /* 可更改 */
        margin-right: 5px;
        width: 36px;
        border: 1px solid rgba(72, 152, 241, 0.3);
        line-height: 48px;
        border-radius: 6px;
    }
 
    .count-flop-point {
        /* 可更改 */
        margin-right: 5px;
        width: 10px;
    }
 
    .count-flop-content {
        font-family: MicrosoftYaHei-Bold;
        text-align: center;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        animation-fill-mode: forwards !important;
    }
 
    .rolling_0 {
        animation: rolling_0 2.1s ease;
    }
 
    @keyframes rolling_0 {
        from {
            transform: translateY(-90%);
        }
        to {
            transform: translateY(0);
        }
    }
 
    .rolling_1 {
        animation: rolling_1 3s ease;
    }
 
    @keyframes rolling_1 {
        from {
            transform: translateY(0);
        }
        to {
            transform: translateY(-10%);
        }
    }
 
    .rolling_2 {
        animation: rolling_2 2.1s ease;
    }
 
    @keyframes rolling_2 {
        from {
            transform: translateY(0);
        }
        to {
            transform: translateY(-20%);
        }
    }
 
    .rolling_3 {
        animation: rolling_3 3s ease;
    }
 
    @keyframes rolling_3 {
        from {
            transform: translateY(0);
        }
        to {
            transform: translateY(-30%);
        }
    }
 
    .rolling_4 {
        animation: rolling_4 2.1s ease;
    }
 
    @keyframes rolling_4 {
        from {
            transform: translateY(0);
        }
        to {
            transform: translateY(-40%);
        }
    }
 
    .rolling_5 {
        animation: rolling_5 3s ease;
    }
 
    @keyframes rolling_5 {
        from {
            transform: translateY(0);
        }
        to {
            transform: translateY(-50%);
        }
    }
 
    .rolling_6 {
        animation: rolling_6 2.1s ease;
    }
 
    @keyframes rolling_6 {
        from {
            transform: translateY(0);
        }
        to {
            transform: translateY(-60%);
        }
    }
 
    .rolling_7 {
        animation: rolling_7 3.1s ease;
    }
 
    @keyframes rolling_7 {
        from {
            transform: translateY(0);
        }
        to {
            transform: translateY(-70%);
        }
    }
 
    .rolling_8 {
        animation: rolling_8 2.1s ease;
    }
 
    @keyframes rolling_8 {
        from {
            transform: translateY(0);
        }
        to {
            transform: translateY(-80%);
        }
    }
 
    .rolling_9 {
        animation: rolling_9 3.6s ease;
    }
 
    @keyframes rolling_9 {
        from {
            transform: translateY(0);
        }
        to {
            transform: translateY(-90%);
        }
    }
</style>

 (2)调用:

<template>
    <div>
        <h2>翻牌器动画:</h2>
        <CountFlop :val="val" />
 
        <h2>翻牌器自定义样式:</h2>
        <div class="myself">
            <CountFlop :val="val2" suffix="rmb" />
        </div> 
    </div> 
</template>
 
<script>
    import CountFlop from '@/components/CountFlop.vue'
    export default {
        components: {
            CountFlop,
        },
        data() {
            return {
                val: 2017,
                val2: 16.6,
            }
        }
    }
</script>
 
<style scoped lang="less">
    .myself {
        height: 32px;
        /deep/ .count-flop {
            height: 32px;
            line-height: 32px;
            font-size: 36px;
            color: red;
        }
        /deep/ .count-flop-box {
            margin-right: 0;
            width: 22px;
            border: 0;
            border-radius: 0;
            line-height: 32px;
        }
        /deep/ .count-flop-point {
            margin-right: 0;
        }
        /deep/ .count-flop-unit {
            font-size: 25px;
        }
    }
</style>

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • 详解vue数据渲染出现闪烁问题

    详解vue数据渲染出现闪烁问题

    本篇文章主要介绍了vue数据渲染出现闪烁问题,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-06-06
  • 解决vue v-for 遍历循环时key值报错的问题

    解决vue v-for 遍历循环时key值报错的问题

    今天小编就为大家分享一篇解决vue v-for 遍历循环时key值报错的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2018-09-09
  • vue-router 4使用实例详解

    vue-router 4使用实例详解

    虽然 vue-router 4 大多数 API 保持不变,但是在 vue3 中以插件形式存在,所以在使用时有一定的变化。接下来就学习学习它是如何使用的
    2021-11-11
  • vue3中如何使用vue-types

    vue3中如何使用vue-types

    vue-types 在 Vue 3 中的使用主要适用于希望进行更细致的 prop 验证的场景,尤其是在 JavaScript 项目中,这篇文章给大家介绍vue3中如何使用vue-types,感兴趣的朋友跟随小编一起看看吧
    2024-04-04
  • Vue.js中v-for指令的用法介绍

    Vue.js中v-for指令的用法介绍

    这篇文章介绍了Vue.js中v-for指令的用法,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2022-03-03
  • VUE动态生成word的实现

    VUE动态生成word的实现

    这篇文章主要介绍了VUE动态生成word的实现,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-07-07
  • Axios学习笔记之使用方法教程

    Axios学习笔记之使用方法教程

    axios是用来做数据交互的插件,最近正在学习axios,所以想着整理成笔记方便大家和自己参考学习,下面这篇文章主要跟大家介绍了关于Axios使用方法的相关资料,需要的朋友们下面来一起看看吧。
    2017-07-07
  • uniapp前端实现微信支付功能全过程(小程序、公众号H5、app)

    uniapp前端实现微信支付功能全过程(小程序、公众号H5、app)

    这篇文章主要介绍了uniapp前端实现微信支付功能的相关资料,通过uniapp开发跨平台应用时,需要处理不同平台的支付方式,包括微信小程序支付、公众号H5支付和App支付,需要的朋友可以参考下
    2024-09-09
  • vue中methods、mounted等的使用方法解析

    vue中methods、mounted等的使用方法解析

    这篇文章主要介绍了vue中methods、mounted等的使用方法解析,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-06-06
  • mpvue将vue项目转换为小程序

    mpvue将vue项目转换为小程序

    这篇文章主要介绍了mpvue将vue项目转换为小程序的相关资料及mpvue开发流程,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
    2018-09-09

最新评论