|
|
@@ -13,7 +13,7 @@ export default {
|
|
|
name: 'word-cloud',
|
|
|
data() {
|
|
|
return {
|
|
|
- timer: 50, // 球体转动速率
|
|
|
+ timer: null, // 球体转动速率
|
|
|
radius: 0, // 词云球体面积大小
|
|
|
dtr: Math.PI / 180, //鼠标滑过球体转动速度
|
|
|
active: false, // 默认加载是否开启转动
|
|
|
@@ -83,7 +83,7 @@ export default {
|
|
|
})
|
|
|
},
|
|
|
beforeDestroy() {
|
|
|
- clearInterval(this.timer)
|
|
|
+ cancelAnimationFrame(this.timer.id)
|
|
|
},
|
|
|
methods: {
|
|
|
// 获取点击文本信息
|
|
|
@@ -101,7 +101,26 @@ export default {
|
|
|
}
|
|
|
this.sineCosine(0, 0, 0)
|
|
|
this.positionAll()
|
|
|
- setInterval(this.update, this.timer)
|
|
|
+ // this.timer = setInterval(this.update, 50)
|
|
|
+ this.timer = setAnimationFrame(() => {
|
|
|
+ this.update()
|
|
|
+ }, 50)
|
|
|
+ function setAnimationFrame(render, time) {
|
|
|
+ var nowTime = 0
|
|
|
+ var lastTime = Date.now()
|
|
|
+ var diffTime = time
|
|
|
+ var timer = {}
|
|
|
+ function animloop() {
|
|
|
+ nowTime = Date.now()
|
|
|
+ if (nowTime - lastTime > diffTime) {
|
|
|
+ lastTime = nowTime
|
|
|
+ render()
|
|
|
+ }
|
|
|
+ timer.id = requestAnimationFrame(animloop)
|
|
|
+ }
|
|
|
+ animloop()
|
|
|
+ return timer
|
|
|
+ }
|
|
|
},
|
|
|
positionAll() {
|
|
|
let phi = 0
|