zoukankan      html  css  js  c++  java
  • 数字变化时的滚动效果(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>
  • 相关阅读:
    Vue中data数据,使用v-model属性绑定第三方插件(例如Jquery的日期插件)无法自动更新
    Mybatis的XML文件调用静态方法
    将博客搬至CSDN
    深入理解Java:类加载机制及反射
    JDBC中Statement与PreparedStatement的区别
    响应实体类
    MD5加密
    idea的注入和自动编译配置
    mybatis三剑客之插件---MyBatis plugins
    通过git从码云克隆项目到本地
  • 原文地址:https://www.cnblogs.com/soonK/p/12641654.html
Copyright © 2011-2022 走看看