vue饿了么ui 进度条 做一个顶部滚动条

dom

<el-main style="position:relative">
          <el-slider v-model="sliderNum" v-show="scrollw>0" :show-tooltip="false" class="indexslider" :min="0" :max="scrollw"   @input="changePage(sliderNum)"></el-slider>
          <div style="width:100%;height:100%;overflow:auto;background:#eee"  @scroll="handleScroll($event)" id="routerbox" ref="scrollbox">
            <router-view></router-view>
          </div>
        </el-main>

js

data:
 domW: 0,
      scrollw: 0, // 滑块最大值
      mainwidth: 0, // 内部盒子宽度
      sliderNum: 0,
      showside: true,
 watch: {
    '$route': function () {
      this.$nextTick(function () {
        this.setw()
        this.defaultUrl = this.$route.path
      })
    },
    // 'getPath',
    sliderNum: function (val) {
      if (isNaN(val)) {
        this.sliderNum = 0
      }
    }
  },
  methods: {
    changePage (sliderNum) {
      this.$nextTick(() => { // 图片列表栏始终左对齐
        if (this.$refs.scrollbox.scrollTo != undefined) {
          this.$refs.scrollbox.scroll({
            left: sliderNum,
            behavior: 'auto'
          })
        } else {
          this.$refs.scrollbox.scrollLeft = sliderNum
        }
      })
    },
    handleScroll (e) {
      this.sliderNum = e.target.scrollLeft
    },
    setw () {
      this.sliderNum = 0
      this.mainwidth = this.$children[0].$children[1].$children[1].$children[1].$el.clientWidth
      this.scrollw = this.mainwidth - this.$refs.scrollbox.clientWidth
    }
  },
  updated () {
    // this.setw()
  },
  mounted () {
    let href = window.location.href
    this.defaultUrl = href.split('/#')[1]
    this.domW = document.body.clientWidth
    this.setw()
    let that = this
    window.onresize = function () {
      that.setw()
      // 立刻设置高度
      that.domW = document.body.clientWidth// 头部处理
      if (that.$refs.tac.$el.clientHeight > that.$refs.aside.$el.clientHeight) {
        that.$refs.side.style.height = `${that.$refs.tac.$el.clientHeight}px`
      } else {
        that.$refs.side.style.height = '100%'
      }
    }
  },
  destroyed () {
    window.onresize=null
  }

css

滚动条样式
::-webkit-scrollbar {width:8px; height:8px; background-color:transparent;cursor: pointer;} /*定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/
::-webkit-scrollbar-track {background-color:#fff;cursor: pointer;} /*定义滚动条轨道 内阴影+圆角*/
::-webkit-scrollbar-thumb {background-color:rgba(144,147,153,.3); border-radius:10px;cursor: pointer;} /*定义滑块 内阴影+圆角*/
.indexslider{
  position: sticky;
  top:0px;
  z-index:1000;
}
.indexslider .el-slider__button{
  display:none;
  width:8px;
  height:8px;
}
.indexslider .el-slider__runway{
  margin:0;
  height:8px;
}
.indexslider .el-slider__bar{
  border-radius:3px;
  height: 8px
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值