VUE 实现 3D词云 旋转词云效果

这篇具有很好参考价值的文章主要介绍了VUE 实现 3D词云 旋转词云效果。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

 效果视频:

3D词云文章来源地址https://www.toymoban.com/news/detail-742824.html

 废话不说直接上代码 :

<template>
    <section class="cloud-bed">
      <div class="cloud-box">
        <span
          v-for="(item, index) in dataList"
          :key="index"
          @click="getDataInfo(item)"
          :style="{color:item.color,background:item.bgColor}"
        >
          {{ item.name }}
        </span>
      </div>
    </section>
  </template>
   
  <script>
    export default {
      name: "word-cloud",
      data() {
        return {
          timer: 50, // 球体转动速率
          radius: 0, // 词云球体面积大小
          dtr: Math.PI/180, //鼠标滑过球体转动速度
          active: false, // 默认加载是否开启转动
          lasta: 0.2, // 上下转动
          lastb: 0.5, // 左右转动
          distr: true,
          tspeed: 0, // 鼠标移动上去时球体转动
          mouseX: 0,
          mouseY: 0,
          tagAttrList: [],
          tagContent: null,
          cloudContent: null,
          sinA: '',
          cosA: '',
          sinB: '',
          cosB: '',
          sinC: '',
          cosC: '',
          dataList: [
            {
              name: '页面卡顿\白屏',
              value: '1',
              bgColor:'rgb(57, 193, 207,0.12)',
              color:'#39c1cf',
            },
            {
              name: '闪退',
              value: '8',
              bgColor:'rgb(66, 105, 245,0.12)',
              color:'#4269f5',
            },
            {
              name: '登录问题',
              value: '9',
              bgColor:'rgb(184, 107, 215,0.12)',
              color:'#b86bd7',
            },
            {
              name: '功能bug',
              value: '3',
              bgColor:'rgb(243, 84, 83,0.12)',
              color:'#f35453',
            },
            {
              name: '无法收到短信',
              value: '6',
              bgColor:'rgb(250, 116, 20,0.12)',
              color:'#FA7414',
            },
            {
              name: '人脸/指纹认证失败',
              value: '10',
              bgColor:'rgb(255, 171, 30,0.12)',
              color:'#FFAB1E',
            },
            {
              name: '功能建议',
              value: '2',
              bgColor:'rgb(136, 104, 217,0.12)',
              color:'#8868D9',
            },
            {
              name: 'UI/UX',
              value: '5',
              bgColor:'rgb(42, 184, 230,0.12)',
              color:'#2AB8E6',
            },
            {
              name: '导航性',
              value: '7',
              bgColor:'rgb(117, 133, 162,0.12)',
              color:'#7585A2',
            },
          ]
        }
      },
      mounted () {
        this.$nextTick(() => {
          this.radius = document.querySelector('.cloud-box').offsetWidth / 2
          this.initWordCloud()
        })
      },
      beforeDestroy () {
        clearInterval(this.timer)
      },
      methods:{
        // 获取点击文本信息
        getDataInfo (item) {
          console.log(item, 'item')
        },
        initWordCloud () {
          this.cloudContent = document.querySelector('.cloud-box');
          this.tagContent = this.cloudContent.getElementsByTagName('span');
          for (let i = 0; i < this.tagContent.length; i++) {
            let tagObj = {};
            tagObj.offsetWidth = this.tagContent[i].offsetWidth;
            tagObj.offsetHeight = this.tagContent[i].offsetHeight;
            this.tagAttrList.push(tagObj);
          }
          this.sineCosine(0, 0, 0);
          this.positionAll();
          this.cloudContent.onmouseover = () => {
            this.active=true;
          };
          this.cloudContent.onmouseout = () => {
            this.active=false;
          };
          this.cloudContent.onmousemove = (ev) => {
            let oEvent = window.event || ev;
            this.mouseX = oEvent.clientX - (this.cloudContent.offsetLeft + this.cloudContent.offsetWidth/2);
            this.mouseY = oEvent.clientY - (this.cloudContent.offsetTop + this.cloudContent.offsetHeight/2);
            this.mouseX/= 5;
            this.mouseY/= 5;
          };
            setInterval(this.update, this.timer);
        },
        positionAll () {
          let phi = 0;
          let theta = 0;
          let max = this.tagAttrList.length;
          let aTmp = [];
          let oFragment = document.createDocumentFragment();
          //随机排序
          for (let i=0; i < this.tagContent.length; i++) {
            aTmp.push(this.tagContent[i]);
          }
          aTmp.sort(() => {
            return Math.random() < 0.5 ? 1 : -1;
          });
          for (let i = 0; i < aTmp.length; i++) {
            oFragment.appendChild(aTmp[i]);
          }
          this.cloudContent.appendChild(oFragment);
          for(let i = 1; i < max + 1; i++){
            if (this.distr) {
              phi = Math.acos(-1 + (2 * i - 1) / max);
              theta = Math.sqrt(max * Math.PI) * phi;
            } else {
              phi = Math.random() * (Math.PI);
              theta = Math.random() * (2 * Math.PI);
            }
            //坐标变换
            this.tagAttrList[i-1].cx = this.radius * Math.cos(theta) * Math.sin(phi);
            this.tagAttrList[i-1].cy = this.radius * Math.sin(theta) * Math.sin(phi);
            this.tagAttrList[i-1].cz = this.radius * Math.cos(phi);
            this.tagContent[i-1].style.left = this.tagAttrList[i-1].cx + this.cloudContent.offsetWidth / 2 - this.tagAttrList[i-1].offsetWidth / 2 + 'px';
            this.tagContent[i-1].style.top = this.tagAttrList[i-1].cy + this.cloudContent.offsetHeight / 2 - this.tagAttrList[i-1].offsetHeight / 2 + 'px';
          }
        },
        update () {
          let angleBasicA;
          let angleBasicB;
   
          if (this.active) {
            angleBasicA = (-Math.min(Math.max(-this.mouseY, -200 ), 200) / this.radius) * this.tspeed;
            angleBasicB = (Math.min(Math.max(-this.mouseX, -200 ), 200) / this.radius) * this.tspeed;
          } else {
            angleBasicA = this.lasta * 0.98;
            angleBasicB = this.lastb * 0.98;
          }
   
          //默认转动是后是否需要停下
          // lasta=a;
          // lastb=b;
   
          // if(Math.abs(a)<=0.01 && Math.abs(b)<=0.01)
          // {
          // return;
          // }
          this.sineCosine(angleBasicA, angleBasicB, 0);
          for(let j = 0; j < this.tagAttrList.length; j++) {
            let rx1 = this.tagAttrList[j].cx;
            let ry1 = this.tagAttrList[j].cy * this.cosA + this.tagAttrList[j].cz * (-this.sinA);
            let rz1 = this.tagAttrList[j].cy * this.sinA + this.tagAttrList[j].cz * this.cosA;
   
            let rx2 = rx1 * this.cosB + rz1 * this.sinB;
            let ry2 = ry1;
            let rz2 = rx1 * (-this.sinB) + rz1 * this.cosB;
   
            let rx3 = rx2 * this.cosC + ry2 * (-this.sinC);
            let ry3 = rx2 * this.sinC + ry2 * this.cosC;
            let rz3 = rz2;
            this.tagAttrList[j].cx = rx3;
            this.tagAttrList[j].cy = ry3;
            this.tagAttrList[j].cz = rz3;
   
            let per = 350 / (350 + rz3);
   
            this.tagAttrList[j].x = rx3 * per - 2;
            this.tagAttrList[j].y = ry3 * per;
            this.tagAttrList[j].scale = per;
            this.tagAttrList[j].alpha = per;
   
            this.tagAttrList[j].alpha = (this.tagAttrList[j].alpha - 0.6) * (10/6);
          }
          this.doPosition();
          this.depthSort();
        },
        doPosition() {
          let len = this.cloudContent.offsetWidth/2;
          let height = this.cloudContent.offsetHeight/2;
          for (let i=0;i < this.tagAttrList.length;i++) {
            this.tagContent[i].style.left = this.tagAttrList[i].cx + len - this.tagAttrList[i].offsetWidth/2 + 'px';
            this.tagContent[i].style.top = this.tagAttrList[i].cy + height - this.tagAttrList[i].offsetHeight/2 + 'px';
            // this.tagContent[i].style.fontSize = Math.ceil(12 * this.tagAttrList[i].scale/2) + 8 + 'px';
            this.tagContent[i].style.fontSize = Math.ceil(12 * this.tagAttrList[i].scale/2) +10 + 'px';
            this.tagContent[i].style.filter = "alpha(opacity="+100 * this.tagAttrList[i].alpha+")";
            this.tagContent[i].style.opacity = this.tagAttrList[i].alpha + 0.2;
          }
        },
        depthSort(){
          let aTmp = [];
          for (let i = 0; i < this.tagContent.length; i++) {
            aTmp.push(this.tagContent[i]);
          }
          aTmp.sort((item1, item2) => item2.cz - item1.cz);
          for (let i = 0; i < aTmp.length; i++) {
            aTmp[i].style.zIndex=i;
          }
        },
        sineCosine (a, b, c) {
          this.sinA = Math.sin(a * this.dtr);
          this.cosA = Math.cos(a * this.dtr);
          this.sinB = Math.sin(b * this.dtr);
          this.cosB = Math.cos(b * this.dtr);
          this.sinC = Math.sin(c * this.dtr);
          this.cosC = Math.cos(c * this.dtr);
        }
      }
    };
  </script>
   
   
  <style scoped>
  .cloud-bed {
    width: 400px;
    height: 400px;
    margin: auto;
  }
  .cloud-box{
      position:relative;
      margin:20px auto 0px;
      width: 100%;
      height: 100%;
      background:	#00000000;
    }
   .cloud-box span{
        position: absolute;
        padding: 3px 6px;
        top: 0px;
        font-weight: bold;
        text-decoration:none;
        left:0px;
        background-image: linear-gradient(to bottom, red, #fff);
        background-clip: text;
        color: transparent;
        width: 50px;
        height: 50px;
        border-radius: 50%;
        text-align: center;
  
        display: flex;
        align-items: center;
        justify-content: center;
  
        /* line-height: 50px;
        overflow:hidden;
        white-space: nowrap;
        text-overflow: ellipsis; */
      }
  </style>
  

到了这里,关于VUE 实现 3D词云 旋转词云效果的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • vue2+three.js实现类似VR、3D全景效果

    效果图: 俩图标是我自己加的前进后退按钮,也是百度了好久,再加上GPT的帮助,才给搞出来。因为需求急,都不看官方文档,百度到一个能跑的demo之后改吧改吧,就先用着了。 下面是代码: 这里 代码有很多用不到的地方和需要优化的地方,我是来不及改了,就先这样吧

    2024年02月15日
    浏览(37)
  • vue2+three.js+blender(实现3d 模型引入并可点击效果)

    2023.9.13今天我学习了如何把3d建模里面的模型引入到vue中,并可以实现拖动,点击的效果: 首先安装: npm install three 相关代码如下:  如果没有图片可以去 Three.js--》建模软件如何加载外部3D模型?_threejs加载3d模型_亦世凡华、的博客-CSDN博客

    2024年02月03日
    浏览(40)
  • 利用js实现matrix3d绕球旋转效果

    小球围成一圈,绕中心轴旋转

    2024年02月08日
    浏览(42)
  • VUE3+ThreeJs实现3D全景场景,可自由旋转视角

    three.js是一个用于在Web上创建三维图形的JavaScript库。它可以用于创建各种类型的三维场景,包括游戏、虚拟现实、建筑和产品可视化等。three.js提供了许多功能和特性,包括3D渲染、光照、材质、几何形状、动画、交互和相机控制等。使用three.js,开发人员可以轻松地创建复杂

    2024年02月11日
    浏览(38)
  • vue echarts实现3D效果柱状图

    在vue2项目里面,研究了哈,这里记录下eacharts 实现3D效果柱状图 在main.js引入eacharts 展示效果:大屏demo

    2024年02月15日
    浏览(35)
  • vue+echarts——实现3D地图+3D柱状图 效果——粗糙代码记录——技能提升

    最近看到同事在弄下面的这个图,这个图是从网上看到的,是某个网站的收费项目: 所以,最后的决定是通过 echarts 中的 3D地图 来写。但是写出来的效果不慎好看。功能是可以实现的。 初版效果图如下: 直接上代码: 我这边是存储到当前文件夹中了。。。 背景颜色是 ec

    2024年02月09日
    浏览(36)
  • vue3 echarts实现3D立体柱状图效果,多柱状图

    使用插件vchart+echarts5.x按需引入实现 需要注意下,底下的椭圆,是在柱子底下“透”出来,颜色应该暗一点,才能视觉上看着有立体感。 成品,还原了大部分设计效果

    2024年02月06日
    浏览(36)
  • CSS3实现图片的3D旋转效果

    准备两张图片,尺寸一样大,本代码中是绕 Y 轴进行旋转(也可以改为 X 轴)。 先看看效果:   代码如下:

    2024年02月12日
    浏览(39)
  • vue3.0 使用echarts与echarts-gl 实现可旋转,可放大3D饼图

    echarts与echarts-gl 实现3D饼图 实现效果: 旋转效果 缩放效果 实现步骤 1、安装echarts npm install echarts npm install echarts-gl 2、页面定义容器 3、js中引入echarts VUE 组件完整源码:

    2024年04月26日
    浏览(30)
  • CSS实现鼠标跟随 3D 旋转效果,让交互活起来

    一淘模板(56admin.com)给大家介绍一下如何使用CSS实现有意思的鼠标跟随 3D 旋转效果,让交互更加生动,希望对大家有所帮助! 今天,群友问了这样一个问题,如下所示的鼠标跟随交互效果,如何实现: 简单分析一下,这个交互效果主要有两个核心: 借助了 CSS 3D 的能力 元

    2024年02月10日
    浏览(63)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包