iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >Vue中怎么实现3D标签云
  • 318
分享到

Vue中怎么实现3D标签云

2023-06-20 16:06:24 318人浏览 安东尼
摘要

这篇文章主要讲解了“Vue中怎么实现3D标签云”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Vue中怎么实现3D标签云”吧!预览:代码:页面部分:<template> 

这篇文章主要讲解了“Vue中怎么实现3D标签云”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Vue中怎么实现3D标签云”吧!

预览:

Vue中怎么实现3D标签云

代码:
页面部分:

<template>  <div class="taGCloud-all"       ref="tagcloudall">    <a v-for="item in tagList" :href="item.url" rel="external nofollow"  :>{{item.name}}</a>  </div></template>

CSS部分:

// 标签云.tagcloud-all {  position: relative;  a {    position: absolute;    top: 0px;    left: 0px;    color: #fff;    font-weight: bold;    text-decoration: none;    padding: 3px 6px;    &:hover {      color: #FF0000;      letter-spacing: 2px;    }  }}

js部分:

export default {  name: "tagcloud",  data() {    return {      tagList: [],      radius: 120,      dtr: Math.PI / 180,      d: 300,      mcList: [],      active: false,      lasta: 1,      lastb: 1,      distr: true,      tspeed: 10,      size: 250,      mouseX: 0,      mouseY: 0,      howElliptical: 1,      oList: null,      oA: null,      sa: 0,      ca: 0,      sb: 0,      cb: 0,      sc: 0,      cc: 0    }  },  methods: {    // 生成随机数    getRandomNum() {      return Math.floor(Math.random() * (255 + 1));    },    // 三角函数角度计算    sineCosine(a, b, c) {      this.sa = Math.sin(a * this.dtr);      this.ca = Math.cos(a * this.dtr);      this.sb = Math.sin(b * this.dtr);      this.cb = Math.cos(b * this.dtr);      this.sc = Math.sin(c * this.dtr);      this.cc = Math.cos(c * this.dtr);    },    // 设置初始定位    positionAll() {      this.$nextTick(() => {      // 注意: 所有的在onReady方法中执行的方法都需要$nextTick确保所有的标签都已经渲染        var phi = 0;        var theta = 0;        var max = this.mcList.length;        var aTmp = [];        var oFragment = document.createDocumentFragment();        // 随机排序        for (let i = 0; i < this.tagList.length; i++) {          aTmp.push(this.oA[i]);        }        aTmp.sort(() => {          return Math.random() < 0.5 ? 1 : -1;        });        for (let i = 0; i < aTmp.length; i++) {          oFragment.appendChild(aTmp[i]);        }        this.oList.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.mcList[i - 1].cx = this.radius * Math.cos(theta) * Math.sin(phi);          this.mcList[i - 1].cy = this.radius * Math.sin(theta) * Math.sin(phi);          this.mcList[i - 1].cz = this.radius * Math.cos(phi);          this.oA[i - 1].style.left = this.mcList[i - 1].cx + this.oList.offsetWidth / 2 - this.mcList[i - 1].offsetWidth / 2 + 'px';          this.oA[i - 1].style.top = this.mcList[i - 1].cy + this.oList.offsetHeight / 2 - this.mcList[i - 1].offsetHeight / 2 + 'px';        }      })    },    // 坐标更新 让标签动起来    update() {      this.$nextTick(() => {           // 注意: 所有的在onReady方法中执行的方法都需要$nextTick确保所有的标签都已经渲染        var a;        var b;        if (this.active) {          a = (-Math.min(Math.max(-this.mouseY, -this.size), this.size) / this.radius) * this.tspeed;          b = (Math.min(Math.max(-this.mouseX, -this.size), this.size) / this.radius) * this.tspeed;        } else {          a = this.lasta * 0.98;          b = this.lastb * 0.98;        }        this.lasta = a;        this.lastb = b;        if (Math.abs(a) <= 0.01 && Math.abs(b) <= 0.01) {          return        }        var c = 0;        this.sineCosine(a, b, c);        for (var j = 0; j < this.mcList.length; j++) {          var rx1 = this.mcList[j].cx;          var ry1 = this.mcList[j].cy * this.ca + this.mcList[j].cz * (-this.sa);          var rz1 = this.mcList[j].cy * this.sa + this.mcList[j].cz * this.ca;          var rx2 = rx1 * this.cb + rz1 * this.sb;          var ry2 = ry1;          var rz2 = rx1 * (-this.sb) + rz1 * this.cb;          var rx3 = rx2 * this.cc + ry2 * (-this.sc);          var ry3 = rx2 * this.sc + ry2 * this.cc;          var rz3 = rz2;          this.mcList[j].cx = rx3;          this.mcList[j].cy = ry3;          this.mcList[j].cz = rz3;          var per = this.d / (this.d + rz3);          this.mcList[j].x = (this.howElliptical * rx3 * per) - (this.howElliptical * 2);          this.mcList[j].y = ry3 * per;          this.mcList[j].scale = per;          this.mcList[j].alpha = per;          this.mcList[j].alpha = (this.mcList[j].alpha - 0.6) * (10 / 6);        }        this.doPosition();        this.depthSort();      })    },    //    doPosition() {      this.$nextTick(() => {            // 注意: 所有的在onReady方法中执行的方法都需要$nextTick确保所有的标签都已经渲染        var l = this.oList.offsetWidth / 2;        var t = this.oList.offsetHeight / 2;        for (var i = 0; i < this.mcList.length; i++) {          this.oA[i].style.left = this.mcList[i].cx + l - this.mcList[i].offsetWidth / 2 + 'px';          this.oA[i].style.top = this.mcList[i].cy + t - this.mcList[i].offsetHeight / 2 + 'px';          this.oA[i].style.fontSize = Math.ceil(12 * this.mcList[i].scale / 2) + 8 + 'px';          // this.oA[i].style.filter = "alpha(opacity=" + 100 * this.mcList[i].alpha + ")";          this.oA[i].style.opacity = this.mcList[i].alpha;        }      })    },    //    depthSort() {      this.$nextTick(() => {            // 注意: 所有的在onReady方法中执行的方法都需要$nextTick确保所有的标签都已经渲染        var aTmp = [];        for (let i = 0; i < this.oA.length; i++) {          aTmp.push(this.oA[i]);        }        aTmp.sort(function (vItem1, vItem2) {          if (vItem1.cz > vItem2.cz) {            return -1;          } else if (vItem1.cz < vItem2.cz) {            return 1;          } else {            return 0;          }        });        for (let i = 0; i < aTmp.length; i++) {          aTmp[i].style.zIndex = i;        }      })    },    // 网络请求 拿到tagList    query() {      // 假装从接口拿回来的数据      let tagListOrg = [        { name: '标签1', url: 'www.baidu.com' },        { name: '标签2', url: 'www.baidu.com' },        { name: '标签3', url: 'www.baidu.com' },        { name: '标签4', url: 'www.baidu.com' },        { name: '标签5', url: 'www.baidu.com' },        { name: '标签6', url: 'www.baidu.com' },        { name: '标签7', url: 'www.baidu.com' },        { name: '标签8', url: 'www.baidu.com' },        { name: '标签9', url: 'www.baidu.com' },        { name: '标签10', url: 'www.baidu.com' },        { name: '标签11', url: 'www.baidu.com' },        { name: '标签12', url: 'www.baidu.com' },        { name: '标签13', url: 'www.baidu.com' },        { name: '标签14', url: 'www.baidu.com' },        { name: '标签15', url: 'www.baidu.com' },        { name: '标签16', url: 'www.baidu.com' },        { name: '标签16', url: 'www.baidu.com' },        { name: '标签16', url: 'www.baidu.com' },        { name: '标签16', url: 'www.baidu.com' },        { name: '标签16', url: 'www.baidu.com' },        { name: '标签16', url: 'www.baidu.com' },        { name: '标签16', url: 'www.baidu.com' },        { name: '标签16', url: 'www.baidu.com' },        { name: '标签16', url: 'www.baidu.com' },        { name: '标签16', url: 'www.baidu.com' },        { name: '标签16', url: 'www.baidu.com' },        { name: '标签16', url: 'www.baidu.com' },        { name: '标签16', url: 'www.baidu.com' },        { name: '标签16', url: 'www.baidu.com' },        { name: '标签17', url: 'www.baidu.com' }      ];      // 给tagList添加随机颜色      tagListOrg.forEach(item => {        item.color = "rgb(" + this.getRandomNum() + "," + this.getRandomNum() + "," + this.getRandomNum() + ")";      })      this.tagList = tagListOrg;      this.onReady();    },    // 生成标签云    onReady() {      this.$nextTick(() => {        this.oList = this.$refs.tagcloudall;        this.oA = this.oList.getElementsByTagName('a')        var oTag = null;        for (var i = 0; i < this.oA.length; i++) {          oTag = {};          oTag.offsetWidth = this.oA[i].offsetWidth;          oTag.offsetHeight = this.oA[i].offsetHeight;          this.mcList.push(oTag);        }        this.sineCosine(0, 0, 0);        this.positionAll();        this.oList.onmouseover = () => {          this.active = true;        }        this.oList.onmouseout = () => {          this.active = false;        }        this.oList.onmousemove = (event) => {          var oEvent = window.event || event;          this.mouseX = oEvent.clientX - (this.oList.offsetLeft + this.oList.offsetWidth / 2);          this.mouseY = oEvent.clientY - (this.oList.offsetTop + this.oList.offsetHeight / 2);          this.mouseX /= 5;          this.mouseY /= 5;        }        setInterval(() => {          this.update()        }, 30);            // 定时器执行 不能写setInterval(this.update(), 30)      })    }  },  created() {    this.$nextTick(() => {      this.query();    })  }}

感谢各位的阅读,以上就是“Vue中怎么实现3D标签云”的内容了,经过本文的学习后,相信大家对Vue中怎么实现3D标签云这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是编程网,小编将为大家推送更多相关知识点的文章,欢迎关注!

--结束END--

本文标题: Vue中怎么实现3D标签云

本文链接: https://www.lsjlt.com/news/298446.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Vue中怎么实现3D标签云
    这篇文章主要讲解了“Vue中怎么实现3D标签云”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Vue中怎么实现3D标签云”吧!预览:代码:页面部分:<template> ...
    99+
    2023-06-20
  • Vue中如何实现3D标签云
    今天小编给大家分享一下Vue中如何实现3D标签云的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下...
    99+
    2024-04-02
  • Vue中实现3D标签云的详细代码
    预览: 代码: 页面部分: <template> <div class="tagcloud-all" ref="tagcloudall"&...
    99+
    2024-04-02
  • 使用vue怎么实现tab标签
    使用vue怎么实现tab标签?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。<template>    <div&n...
    99+
    2023-06-15
  • vue实现tab标签(标签超出自动滚动)
    当创建的tab标签超出页面可视区域时自动滚动一个tab标签距离,并可手动点击滚动tab标签,实现效果请看GIF图 效果预览GIF图 <template> &...
    99+
    2024-04-02
  • vue怎么实现input框禁止输入标签
    这篇“vue怎么实现input框禁止输入标签”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“vue怎么实现input框禁止输入...
    99+
    2023-06-29
  • vue怎么实现修改标签中的内容:id class style
    本篇内容介绍了“vue怎么实现修改标签中的内容:id class style”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成...
    99+
    2023-07-02
  • vue实现修改标签中的内容:idclassstyle
    目录vue修改标签的内容:id class stylev-bind,v-model注意动态改变class和style的一些方法使用$event下面的函数处理vue修改标签的内容:id...
    99+
    2024-04-02
  • vue+echarts怎么实现3D柱形图
    这篇文章主要介绍了vue+echarts怎么实现3D柱形图的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇vue+echarts怎么实现3D柱形图文章都会有所收获,下面我们一起来看看吧。效果如下:1、安装echa...
    99+
    2023-06-29
  • vue-router如何实现tab标签页
    这篇文章主要介绍了vue-router如何实现tab标签页,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。vue-router 是 Vue.j...
    99+
    2024-04-02
  • vue模板标签怎么用
    这篇文章将为大家详细讲解有关vue模板标签怎么用,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。模板标签的另一种用途该template标签可以在模板内的任何地方使用,以更好地组织代码。我喜欢用它来简化v-i...
    99+
    2023-06-27
  • ajax中怎么实现标签导航功能
    ajax中怎么实现标签导航功能,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。 主要函数:function&nb...
    99+
    2024-04-02
  • vue实现input框禁止输入标签
    目录vue input框禁止输入标签vue input框的禁用和可输入vue input框禁止输入标签 <input type="search" placeholder="请输...
    99+
    2024-04-02
  • vue怎么实现3D切换滚动效果
    本篇内容介绍了“vue怎么实现3D切换滚动效果”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!这个是最终的一个效果,点击左右小箭头,实现滚动效...
    99+
    2023-06-29
  • vue中怎么使用embed标签PDF预览
    今天小编给大家分享一下vue中怎么使用embed标签PDF预览的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。使用embed标...
    99+
    2023-06-30
  • vue在html标签{{}}中怎么调用函数
    这篇文章主要介绍“vue在html标签{{}}中怎么调用函数”,在日常操作中,相信很多人在vue在html标签{{}}中怎么调用函数问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”vue在html标签{{}}中...
    99+
    2023-07-05
  • html中怎么用标签实现文本分段
    这篇文章主要介绍了html中怎么用标签实现文本分段的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇html中怎么用标签实现文本分段文章都会有所收获,下面我们一起来看看吧。 ...
    99+
    2024-04-02
  • Vue使用video标签实现视频播放
    本文项目为大家分享了Vue使用video标签实现视频播放的具体代码,供大家参考,具体内容如下 项目需求:动态显示视频滚动条、禁止视频下载、播放时每5s更新当前时长、每10分钟暂停视频...
    99+
    2024-04-02
  • vue中怎么使用h5 video标签实现弹窗播放本地视频
    这篇“vue中怎么使用h5 video标签实现弹窗播放本地视频”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“vue...
    99+
    2023-06-30
  • vue vue-esign签字板的demo怎么实现
    本篇内容主要讲解“vue vue-esign签字板的demo怎么实现”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“vue vue-esign签字板的demo怎么实现”吧!vu...
    99+
    2023-06-30
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作