element-ui Ant Design Slider进度条鼠标悬停展示鼠标悬停的当前时间

在当前html 节点做移入获取鼠标在div 的x轴,然后div 的宽度/ max值,结算出每个节点的值,在根据

鼠标的X位置 * 每个节点的值,就是当前div悬停的位置

<template>
    <div>
        <a-slider style="margin-top: 100px;" :tooltip-visible="true"  :autoFocus="autoFocus" :min="min" :max="max" :value="value" id="test" :default-value="value" @change="onChange"/>
        <div style="padding: 20px;background: red;color: #fff;position: fixed;display: inline-block;top: 30px;" 
            v-show="isActive" id="popover" v-html="x">
        </div>
    </div>
</template>
data() {
        return {
            min:0,
            max:100,
            value:1,
            autoFocus:true,
            x:0,
            y:0,
            isActive:false
        }
    },
mounted() {
        var temp = document.getElementsByClassName('ant-slider-step')[0]
        var pop = document.getElementById('popover')
        var _this = this
        temp.onmousemove = function(ev){  
            ev = ev || window.event;           
            var offsetX = ev.offsetX
            var xwidth = _this.max / temp.clientWidth     //每份是多少
            _this.x = offsetX * xwidth
            pop.style.left = `${ev.screenX - pop.clientWidth/2}px`
            //top 固定的 是进度条的上方
            pop.style.top = `${temp.offsetTop + 30}px`
            _this.isActive = true
            console.log(ev.screenX, ev.screenY);  
        }
        temp.onmouseout = function(){  
            _this.isActive = false;  
        }
    },

有条件的可以加个渐入的动画

优先建议用绝对定位,相对于temp,不建议用窗口定位
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值