数字变化时的滚动效果(VUE)组件化

1.外部引入

styleHeight:样式的高度,Number: 数字大小

<compute-number

:styleHeight="44"

:number="Number(1905)"

>

</compute-number>

2.组件代码

<template>

<div id="demo">

<div class="nwwest-roll" :style="{‘height‘: styleHeight + ‘px‘}" id="nwwest-roll">

<ul id="roll-ul" class="roll-ul">

<li v-for="(item, index) in list"  :style="{‘height‘: styleHeight + ‘px‘}" ref="rollul" class="rollLi" :class="{anim:animate==true}">

<span class="name">{{item}}</span>

</li>

</ul>

</div>

</div>

</template>

<script>

export default {

// 此处是模拟数字变化,所以数字都不会改变,

props: {

number: {

type: Number,

default: 0

},

styleHeight: {

type: Number,

default: 0

}

},

watch: {

number (newValue, oldValue) {

this.list[1] = newValue

this.list[0] = oldValue

this.num = newValue;

}

},

data () {

return {

animate: true,

list: [this.number, this.number],

num: this.number,

newNum: this.number,

timeout: ‘‘,

timeInterval: ‘‘

}

},

mounted () {

this.timeInterval = setInterval(() => {

this.scroll(this.number);

}, 4000);

},

beforeDestroy() {

clearInterval(this.timeout)

clearInterval(this.timeInterval)

},

methods: {

scroll(num){

let con1 = this.$refs.rollul;

/* styleHeight */

// let marginTopHeight = (this.styleHeight - 10) + ‘px‘

con1[0].style.marginTop = 0;

this.animate = !this.animate;

var that = this;

that.timeout = setTimeout(() =>{

that.list[1] = num

con1[0].style.marginTop = -this.styleHeight + ‘px‘;

that.animate = !that.animate;

setTimeout(() => {

that.list[0] = num

}, 1000);

}, 80)

}

}

}

</script>

<style lang="" scoped>

.nwwest-roll {

overflow: hidden;

}

.nwwest-roll .name{

display: inline-block;

}

.roll-ul {

list-style: none;

padding: 0;

margin: 0;

}

.anim {

transition: all 1s;

}

</style>

原文地址:https://www.cnblogs.com/soonK/p/12641654.html

时间: 2024-08-30 07:13:57

数字变化时的滚动效果(VUE)组件化的相关文章

vue组件化的应用

前言:vue组件化的应用涉及到vue-cli的内容,所以在应用之前是需要安装node和vue-cli的,具体如何安装我就不一一赘述了.可能一会儿我心情好的时候,可以去整理一下. 1.应用的内容:在一个页面中,需要一个固定的内容,这个内容可以多次引用,那么就可以考虑把他分离出来,在下次需要的时候,实现引用就好. 比如: <input type="text" v-model="content" > <button @click = addList>

前端框架Vue自学之Vue组件化开发(三)

终极目标:掌握和使用Vue(全家桶:Core+Vue-router+Vuex) 本博客目的:记录Vue学习的进度和心得(Vue组件化开发) 内容:通过官网说明,掌握Vue组件化开发. 正文: Vue组件化开发 一.认识组件化 原文地址:https://www.cnblogs.com/xinkuiwu/p/12037281.html

vue组件化之模板优化及注册组件语法糖

vue组件化之模板优化及注册组件语法糖 vue组件化 模板 优化 在 https://www.cnblogs.com/singledogpro/p/12054895.html 这里我们对vue.js进行了初体验,输出了经典的hello world.但是在这个过程遇到了编程最恶心的事情----字符串拼接. enter description here vue.extend函数需要一个对象,这个对象的属性是个模板,这个模板的源码是H5. 模板优化 创建组件构造器 在JavaScript里面写H5代码

Vue组件化开发

一. 通过axios实现数据请求 1. json简介 json是 JavaScript Object Notation 的首字母缩写,单词的意思是javascript对象表示法,这里说的json指的是类似于javascript对象的一种数据格式. json的作用:在不同的系统平台,或不同编程语言之间传递数据. 1.1 json数据的语法 json数据对象类似于JavaScript中的对象,但是它的键对应的值里面是没有函数方法的,值可以是普通变量,不支持undefined,值还可以是数组或者jso

vue组件化编程

一:vue项目目录 build : webpack.base.conf.js : config --> index.js 二:组件化编程相关文件分析 1.主页面 index.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initi

vue组件化开发-vuex状态管理库

Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化.Vuex 也集成到 Vue 的官方调试工具 devtools extension,提供了诸如零配置的 time-travel 调试.状态快照导入导出等高级调试功能. 以上是vuex的官方文档对vuex的介绍,官方文档对vuex的用法进行了详细的说明.这里就不再细讲vuex的各个用法,写这篇博客的目的只是帮助部分同学更快地理解并上手vuex.

vue组件化

全局组件 <!DOCTYPE html> <html> <head> <title>vue</title> <!-- <script src="./vue.js"></script> --> <script src="http://cdn.staticfile.org/vue/2.6.10/vue.common.dev.js"></script>

vue组件化开发实战 - 实现简易ElementUI的Form表单组件

Input 组件 功能: 进行数据双绑 通知FormItem组件校验 <template> <div> <input :type="type" :value="value" @input="onInput" v-bind="$attrs" > </div> </template> <script> export default { inheritAttrs

前端面试项目冲刺,京东金融Vue组件化实战

<section>课程地址 http://icourse8.com/vue_jujinahua.html </section> 章节信息第1章 课程介绍第2章 环境及知识准备第3章 业务开发流程与工程构建安装第4章 项目设计与原理分析第5章 京东金融首页第6章 京东金融理财页第7章 京东金融白条页第8章 京东金融众筹页第9章 活动专题页第11章 工程构建详解第12章 面试知识点与技巧第13章 课程总结第14章 直播视频<前端人的危机如何破解> public class