vue + css气泡图动态气泡图

<div id="scatter">
    <ul class="bubbleUl" id="bubbleUl">
      <li v-for="item in bubbleData" :key="item.value" class="bubbleLi">
        <div class="textBubble">
          <span> {{ item.value }}</span>
        </div>
        <!-- 提示-->
        <div class="topDiv">
          <div
            style="width: 126px;height: 60px;background: rgba(0, 237, 237, 0.1);position:relative;">
            <div
              style="
                position: absolute;
                top: 0;
                left: 0;
                width: 18px;
                height: 6px;
                border-left: 1px solid #0be2f0;
                border-top: 1px solid #0be2f0;
              "
            ></div>
            <div
              style="
                color: rgba(0, 255, 255, 1);
                padding: 0px 20px;
                font-size: 12px;
                line-height: 30px;
                font-weight: 400;
                font-family: PingFang SC;
              "
            >
              <p>
                <span>{{ item.name }}</span>
              </p>
              <p>
                <span style="margin-right: 3px">{{ item.value }}</span
                ><span></span>
              </p>
            </div>
            <div
              style="
                position: absolute;
                bottom: 0;
                right: 0;
                width: 18px;
                height: 6px;
                border-right: 1px solid #0be2f0;
                border-bottom: 1px solid #0be2f0;
              "
            ></div>
          </div>
        </div>
      </li>
    </ul>
  </div>
<script>
export default {
  name: 'bubbleView',
  data () {
    return {
      bubbleData: [],
      scatterWidth: 0,
      scatterHeight: 0
    }
  },
  mounted () {
    this.initScatter()
    window.addEventListener('resize', this.initScatter)
  },
  methods: {
    MouseEvent () {
      let ul
      let li

      this.$nextTick(() => {
        // 获取dome节点
        ul = document.getElementById('bubbleUl')
        li = ul.querySelectorAll('.bubbleLi')
        var TabArrayLi = Array.prototype.slice.call(li, 0)
        var clientHeight = document.body.clientHeight // 获取可是区域高度
        var clientWidth = document.body.clientWidth // 获取可视区域宽度
        // 遍历节点
        TabArrayLi.forEach((element) => {
          // 鼠标进入气泡是的操作
          element.onmouseover = (e) => {
            //  e.clientX,e.clientY  鼠标到可是区域的宽高
            element.style.animationPlayState = 'paused'
            element.childNodes[1].style.display = 'block'
            if (
              clientHeight - e.clientY - 50 > this.scatterHeight * 0.5 &&
              clientWidth - e.clientX > this.scatterWidth * 0.5
            ) {
              element.childNodes[1].style.top = '100%'
              element.childNodes[1].style.left = '0%'
            } else if (
              clientHeight - e.clientY - 50 > this.scatterHeight * 0.5 &&
              clientWidth - e.clientX < this.scatterWidth * 0.5
            ) {
              element.childNodes[1].style.top = '100%'
              element.childNodes[1].style.left = '-100%'
            } else if (
              clientHeight - e.clientY - 50 < this.scatterHeight * 0.5 &&
              clientWidth - e.clientX > this.scatterWidth * 0.5
            ) {
              element.childNodes[1].style.top = '-100%'
              element.childNodes[1].style.left = '0%'
            } else if (
              clientHeight - e.clientY - 50 < this.scatterHeight * 0.5 &&
              clientWidth - e.clientX < this.scatterWidth * 0.5
            ) {
              element.childNodes[1].style.top = '-100%'
              element.childNodes[1].style.left = '-100%'
            }
          }
          // 鼠标移出时的操作
          element.onmouseout = (e) => {
            element.style.position = 'relative'
            element.style.animationPlayState = 'running'
            element.childNodes[1].style.display = 'none'
          }
        })
      })
    },
    initScatter () {
      this.windowAd()
      this.bubbleData = [
        { value: 1, name: '类目一' },
        { value: 10, name: '类目二' },
        { value: 1000, name: '类目三' },
        { value: 120000, name: '类目四' },
        { value: 100, name: '类目五' },
        { value: 10000, name: '类目6' },
        { value: 2000000, name: '类目7' },
        { value: 88, name: '类目五' },
        { value: 19990000, name: '类目6' },
        { value: 110000000, name: '类目7' }
      ]
      this.MouseEvent()
    },

    //  获取初始 scatter 的宽高
    windowAd () {
      const id = document.getElementById('scatter')
      this.scatterWidth = id.clientWidth
      this.scatterHeight = id.clientHeight
    }
  },
  beforeDestroy () {
    window.removeEventListener('resize', this.initScatter)
  }
}
</script>
<style lang="scss" scoped>
#scatter {
  width: calc(100% - 20px);
  height: calc(90% - 5px);
  margin-top: 10%;
  padding: 0 10px;
  overflow: hidden;
  display: flex;
  position: relative;
}

ul {
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 100%;
  padding-top: 10%;
  margin: auto;
  display: flex;
  justify-content: space-around;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
}
li {
  width: 60px;
  height: 60px;
  line-height: 60px;
  text-align: center;
  flex-shrink: 0;
  border-radius: 50%;
  background: url("/img");  // 气泡图片,也可以时颜色
  background-size: 100% 100%;
  color: rgba(167, 254, 254, 1);
  font-size: 14px;
  font-family: PingFang SC;
  font-weight: 400;
  animation: move 3s infinite 1s linear;

  .textBubble {
    width: 80%;
    height: 80%;
    margin: auto;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    -o-text-overflow: ellipsis;
    animation-name: itemfloat;
    animation-timing-function: linear;
    animation-fill-mode: both;
    animation-iteration-count: infinite;
    position: relative;
    cursor: pointer;
    // z-index: 99;
  }

  .topDiv {
    width: 100%;
    height: 100%;
    position: absolute;
    // background: #ccc;
    top: 50%;
    left: 0;
    display: none;
    transition: display 2s;
  }
}
@for $i from 1 to 10 {
  li:nth-child(#{$i}) {
    animation-duration: #{random(1000) / 1000 + 5}s;
    animation-delay: #{random(1000) / 1000 + 1}s;
  }
}
@keyframes move {
  0% {
    transform: translate(0, 0);
  }
  100% {
    transform: translate(0, -600%);
  }
}
</style>


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值