电脑知识|欧美黑人一区二区三区|软件|欧美黑人一级爽快片淫片高清|系统|欧美黑人狂野猛交老妇|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网

您的位置:首頁技術文章
文章詳情頁

Vue中實現(xiàn)3D標簽云的詳細代碼

瀏覽:8日期:2022-09-28 10:25:36

預覽:

Vue中實現(xiàn)3D標簽云的詳細代碼

代碼:頁面部分:

<template> <div ref='tagcloudall'> <a v-for='item in tagList' :href='http://www.hdgsjgj.cn/bcjs/item.url' rel='external nofollow' :style='’color:’ + item.color + ’;top: 0;left: 0;filter:none;’'>{{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: { // 生成隨機數(shù) getRandomNum() { return Math.floor(Math.random() * (255 + 1)); }, // 三角函數(shù)角度計算 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方法中執(zhí)行的方法都需要$nextTick確保所有的標簽都已經(jīng)渲染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方法中執(zhí)行的方法都需要$nextTick確保所有的標簽都已經(jīng)渲染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方法中執(zhí)行的方法都需要$nextTick確保所有的標簽都已經(jīng)渲染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方法中執(zhí)行的方法都需要$nextTick確保所有的標簽都已經(jīng)渲染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;} }) }, // 網(wǎng)絡請求 拿到tagList query() { // 假裝從接口拿回來的數(shù)據(jù) 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); // 定時器執(zhí)行 不能寫setInterval(this.update(), 30) }) } }, created() { this.$nextTick(() => { this.query(); }) }}

到此這篇關于Vue中實現(xiàn)3D標簽云的文章就介紹到這了,更多相關Vue 3D標簽云內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持好吧啦網(wǎng)!

標簽: Vue
相關文章:
主站蜘蛛池模板: 艾乐贝拉细胞研究中心 | 国家组织工程种子细胞库华南分库 | 优考试_免费在线考试系统_培训考试系统_题库系统_组卷答题系统_匡优考试 | 钢托盘,铁托盘,钢制托盘,镀锌托盘,饲料托盘,钢托盘制造商-南京飞天金属13260753852 | 【德信自动化】点胶机_全自动点胶机_自动点胶机厂家_塑料热压机_自动螺丝机-深圳市德信自动化设备有限公司 | 120kv/2mA直流高压发生器-60kv/2mA-30kva/50kv工频耐压试验装置-旭明电工 | 室内室外厚型|超薄型|非膨胀型钢结构防火涂料_隧道专用防火涂料厂家|电话|价格|批发|施工 | 开锐教育-学历提升-职称评定-职业资格培训-积分入户 | 商秀—企业短视频代运营_抖音企业号托管 | 法钢特种钢材(上海)有限公司 - 耐磨钢板、高强度钢板销售加工 阀门智能定位器_电液动执行器_气动执行机构-赫尔法流体技术(北京)有限公司 | 浙江华锤电器有限公司_地磅称重设备_防作弊地磅_浙江地磅售后维修_无人值守扫码过磅系统_浙江源头地磅厂家_浙江工厂直营地磅 | 钢结构厂房造价_钢结构厂房预算_轻钢结构厂房_山东三维钢结构公司 | 石家庄救护车出租_重症转院_跨省跨境医疗转送_活动赛事医疗保障_康复出院_放弃治疗_腾康26年医疗护送转诊团队 | 陕西视频监控,智能安防监控,安防系统-西安鑫安5A安防工程公司 | 非标压力容器_碳钢储罐_不锈钢_搪玻璃反应釜厂家-山东首丰智能环保装备有限公司 | 赛默飞Thermo veritiproPCR仪|ProFlex3 x 32PCR系统|Countess3细胞计数仪|371|3111二氧化碳培养箱|Mirco17R|Mirco21R离心机|仟诺生物 | 膜结构车棚|上海膜结构车棚|上海车棚厂家|上海膜结构公司 | 合肥白癜风医院_合肥治疗白癜风医院_合肥看白癜风医院哪家好_合肥华研白癜风医院 | 震动筛选机|震动分筛机|筛粉机|振筛机|振荡筛-振动筛分设备专业生产厂家高服机械 | 重庆轻质隔墙板-重庆安吉升科技有限公司 | 太阳能发电系统-太阳能逆变器,控制器-河北沐天太阳能科技首页 | 潍坊大集网-潍坊信息港-潍坊信息网 | 医养体检包_公卫随访箱_慢病随访包_家签随访包_随访一体机-济南易享医疗科技有限公司 | 铝镁锰板厂家_进口钛锌板_铝镁锰波浪板_铝镁锰墙面板_铝镁锰屋面-杭州军晟金属建筑材料 | Eiafans.com_环评爱好者 环评网|环评论坛|环评报告公示网|竣工环保验收公示网|环保验收报告公示网|环保自主验收公示|环评公示网|环保公示网|注册环评工程师|环境影响评价|环评师|规划环评|环评报告|环评考试网|环评论坛 - Powered by Discuz! | 工业淬火油烟净化器,北京油烟净化器厂家,热处理油烟净化器-北京众鑫百科 | 工业淬火油烟净化器,北京油烟净化器厂家,热处理油烟净化器-北京众鑫百科 | 氮化镓芯片-碳化硅二极管 - 华燊泰半导体 | 活性氧化铝球|氧化铝干燥剂|分子筛干燥剂|氢氧化铝粉-淄博同心材料有限公司 | 广州办公室设计,办公室装修,写字楼设计,办公室装修公司_德科 | 深圳诚暄fpc首页-柔性线路板,fpc柔性线路板打样生产厂家 | 北京京云律师事务所| SPC工作站-连杆综合检具-表盘气动量仪-内孔缺陷检测仪-杭州朗多检测仪器有限公司 | 硫酸亚铁-聚合硫酸铁-除氟除磷剂-复合碳源-污水处理药剂厂家—长隆科技 | 高铝矾土熟料_细粉_骨料_消失模_铸造用铝矾土_铝酸钙粉—嵩峰厂家 | 中药二氧化硫测定仪,食品二氧化硫测定仪|俊腾百科 | 杜甫仪器官网|实验室平行反应器|升降水浴锅|台式低温循环泵 | 【北京写字楼出租_写字楼租赁_办公室出租网/出售】-远行地产官网 | 西安文都考研官网_西安考研辅导班_考研培训机构_西安在职考研培训 | 定硫仪,量热仪,工业分析仪,马弗炉,煤炭化验设备厂家,煤质化验仪器,焦炭化验设备鹤壁大德煤质工业分析仪,氟氯测定仪 | 诗词大全-古诗名句 - 古诗词赏析| 中山市派格家具有限公司【官网】 |