<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(() => {
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) => {
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()
},
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>