JS 自定义的悬浮窗被浏览器遮挡问题解决方案

 

遮挡问题解决思路,首先拿到外层的DOM元素div的宽高,然后根据鼠标悬浮事件的元素e  e.clientX表距离页面窗口宽的位置 e.clientY代表距离页面窗口高的位置

然后设置这个悬浮窗为200px

那个这个div的宽高

dom.getElementById('xxxx').cliengHeight

dom.getElementById('xxxx').cliengWdith

如果clientHeight  -  e.clientY < 200 则让当前悬浮元素的top位置往上加200px 这样就不会被遮挡

同理 clientWdith -  e.clientX < 200 则让当前悬浮元素的left位置往左减200px 就不会被遮挡

move鼠标悬浮事件

      move(e) {
        const dom = document.getElementById('fullscreen')
        if (this.$refs.svgrow && this.$refs.tipdiv) {
          const x = Math.round(this.$refs.svgrow.clientWidth / 2)
          const y = Math.round(this.$refs.svgrow.clientHeight / 2)
          if (x > e.clientX) {
            this.clientX = e.clientX + 10 + 'px'
          }
          if (x < e.clientX && y < e.clientY) {
            this.clientY = e.clientY + 10 + 'px'
            this.clientX = e.clientX - this.$refs.tipdiv.clientWidth - 10 + 'px'
          } else if (x < e.clientX) {
            this.clientX = e.clientX - this.$refs.tipdiv.clientWidth - 10 + 'px'
          } else if (y < e.clientY) {
            this.clientY = e.clientY - 70 + 'px'
          }
          if (y > e.clientY) {
            this.clientY = e.clientY + 10 + 'px'
          }
          const clientHeight = dom.clientHeight
          const clientWidth = dom.clientWidth
          if(clientHeight - e.clientY < 200){
            this.clientY =  e.clientY - 200 + 'px'
            this.clientX = e.clientX + 20 + 'px'
          }else{
            this.clientY = e.clientY - 50 + 'px'
            this.clientX = e.clientX + 20 +'px'
          }
          if(clientWidth - e.clientX < 200){
            this.clientX = e.clientX - 250 + 'px'
          }else{
            this.clientX = e.clientX + 10 +'px'
          }
        }
      },

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

沉默是金~

你的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值