zoukankan      html  css  js  c++  java
  • 滚动条 scrollTop 平滑滑动

    vue 写法 平滑滑动
     
      gotoRirser (num, index) {
          let that = this
          let elt = this.elt
          let total = 0
          let distance = 0
          let step = 14
          let enterBox = this.enterBox
          function smoothDown () {
            let td = parseInt((total - distance) / 10)
            if (td > step) {
              distance = distance + td
              enterBox.scrollTop = distance
              setTimeout(smoothDown, 10)
            } else {
              enterBox.scrollTop = total
              that.leftTIndex = setTimeout(() => {
                that.scrollLock = true
                that.setLiTyDatasAll()
              }, 1000)
            }
          }
    
          // 向上滑动
          function smoothUp () {
            let td = (distance - total) / 10
            if (td > step) {
              distance -= td
              enterBox.scrollTop = distance
              setTimeout(smoothUp, 10)
            } else {
              enterBox.scrollTop = total
              that.rightTIndex = setTimeout(() => {
                that.scrollLock = true
                that.setLiTyDatasAll()
              }, 1000)
            }
          }
          setTimeout(() => {
            for (let i = index - 1; i >= 0; i--) {
              let n = this.allBtns[i].num
              let eNode = enterBox.querySelector('#' + elt + n)
              total += eNode.clientHeight
            }
            distance = this.enterBox.scrollTop
            this.scrollLock = false
            if (this.rightTIndex) {
              clearTimeout(this.rightTIndex)
            }
            if (this.leftTIndex) {
              clearTimeout(this.leftTIndex)
            }
            if (total > distance) {
              smoothDown()
            } else {
              smoothUp()
            }
          }, 20)
        },
    View Code

      

    jjyy 兢兢业业 yyjj
  • 相关阅读:
    oracle的网络服务名和监听程序
    ArcGIS 产品许可模型
    老鸟对菜鸟的一些建议(转)
    ajax简介(转载)
    dim redim
    投影选择的一般原则
    *.prj文件
    cup性能对比感受
    treeview 数据库 递归
    简论两句话
  • 原文地址:https://www.cnblogs.com/ljyyjj/p/11264799.html
Copyright © 2011-2022 走看看