プレビュー: コード: <テンプレート> <div class="タグクラウド-all" ref="タグクラウドall"> <a v-for="tagList 内のアイテム" :href="item.url" rel="外部 nofollow" :style="'color:' + item.color + ';top: 0;left: 0;filter:none;'">{{item.name}}</a> </div> </テンプレート> CSS部分: // タグクラウド.tagcloud-all { 位置: 相対的; { 位置: 絶対; 上: 0px; 左: 0px; 色: #fff; フォントの太さ: 太字; テキスト装飾: なし; パディング: 3px 6px; &:ホバー{ 色: #FF0000; 文字間隔: 2px; } } } JS部分: エクスポートデフォルト{ 名前:「タグクラウド」、 データ() { 戻る { タグリスト: [], 半径: 120, dtr: Math.PI / 180、 d: 300, mcリスト: [], アクティブ: false、 ラスト: 1, 最終b: 1, 分布: 真、 tスピード: 10, サイズ: 250, マウスX: 0, マウスY: 0, howElliptical: 1, oリスト: null、 oA: ヌル、 sa: 0, 約: 0, sb: 0, CB: 0, SC: 0, cc: 0 } }, メソッド: { // 乱数を生成する getRandomNum() { 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 シータ = 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(() => { Math.random() < 0.5 ? 1 : -1 を返します。 }); (i = 0 とします; i < aTmp.length; i++) { oFragment.appendChild(aTmp[i]); } this.oList.appendChild(oFragment); (i = 1; i < max + 1; i++) の場合 { if (this.distr) { φ = Math.acos(-1 + (2 * i - 1) / 最大値); シータ = Math.sqrt(max * Math.PI) * ファイ; } それ以外 { phi = Math.random() * (Math.PI); θ = 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; アクティブの場合 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; } それ以外 { a = this.lasta * 0.98; 最後のbの値を返します。 } this.lasta = a; this.lastb = b; (Math.abs(a) <= 0.01 && Math.abs(b) <= 0.01) の場合 { 戻る } var c = 0; this.sineCosine(a, b, c); (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 * あたり; this.mcList[j].scale = あたり; this.mcList[j].alpha = あたり; this.mcList[j].alpha = (this.mcList[j].alpha - 0.6) * (10 / 6); } this.doPosition(); this.depthSort(); }) }, // 位置合わせ() { this.$nextTick(() => { // 注: onReady メソッドで実行されるすべてのメソッドでは、すべてのラベルがレンダリングされていることを確認するために $nextTick が必要です var l = this.oList.offsetWidth / 2; var t = this.oList.offsetHeight / 2; (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; } }) }, // 深さソート() { this.$nextTick(() => { // 注: onReady メソッドで実行されるすべてのメソッドでは、すべてのラベルがレンダリングされていることを確認するために $nextTick が必要です var aTmp = []; (i = 0 とします; i < this.oA.length; i++) { aTmp.push(this.oA[i]); } aTmp.sort(関数 (vItem1, vItem2) { (vItem1.cz > vItem2.cz) の場合 { -1 を返します。 } そうでない場合 (vItem1.cz < vItem2.cz) { 1 を返します。 } それ以外 { 0を返します。 } }); (i = 0 とします; i < aTmp.length; i++) { aTmp[i].style.zIndex = i; } }) }, // タグリストを取得するためのネットワーク要求 クエリ() { // インターフェースからデータを取得するふりをする let tagListOrg = [ { 名前: 'ラベル 1'、 URL: 'www.baidu.com' }, { 名前: 'ラベル 2'、 URL: 'www.baidu.com' }, { 名前: 'タグ 3'、 URL: 'www.baidu.com' }, { 名前: 'ラベル 4'、 URL: 'www.baidu.com' }, { 名前: 'タグ 5'、 URL: 'www.baidu.com' }, { 名前: 'タグ 6'、 URL: 'www.baidu.com' }, { 名前: 'タグ 7'、 URL: 'www.baidu.com' }, { 名前: 'ラベル 8'、 URL: 'www.baidu.com' }, { 名前: 'タグ 9'、 URL: 'www.baidu.com' }, { 名前: 'ラベル 10'、 URL: 'www.baidu.com' }, { 名前: 'ラベル 11'、 URL: 'www.baidu.com' }, { 名前: 'ラベル 12'、 URL: 'www.baidu.com' }, { 名前: 'タグ 13'、 URL: 'www.baidu.com' }, { 名前: 'タグ 14'、 URL: 'www.baidu.com' }, { 名前: 'タグ 15'、 URL: 'www.baidu.com' }, { 名前: 'タグ 16'、 URL: 'www.baidu.com' }, { 名前: 'タグ 16'、 URL: 'www.baidu.com' }, { 名前: 'タグ 16'、 URL: 'www.baidu.com' }, { 名前: 'タグ 16'、 URL: 'www.baidu.com' }, { 名前: 'タグ 16'、 URL: 'www.baidu.com' }, { 名前: 'タグ 16'、 URL: 'www.baidu.com' }, { 名前: 'タグ 16'、 URL: 'www.baidu.com' }, { 名前: 'タグ 16'、 URL: 'www.baidu.com' }, { 名前: 'タグ 16'、 URL: 'www.baidu.com' }, { 名前: 'タグ 16'、 URL: 'www.baidu.com' }, { 名前: 'タグ 16'、 URL: 'www.baidu.com' }, { 名前: 'タグ 16'、 URL: 'www.baidu.com' }, { 名前: 'タグ 16'、 URL: 'www.baidu.com' }, { 名前: 'タグ 16'、 URL: 'www.baidu.com' }, { 名前: 'タグ 17'、 URL: 'www.baidu.com' } ]; // タグリストにランダムな色を追加します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; (var i = 0; i < this.oA.length; i++) { oタグ = {}; 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 = (イベント) => { var oEvent = window.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; } 間隔を設定する(() => { this.update() }, 30); // タイマー実行では setInterval(this.update(), 30) を書き込むことができません }) } }, 作成された() { this.$nextTick(() => { this.query(); }) } } Vue での 3D タグ クラウドの実装に関するこの記事はこれで終わりです。Vue 3D タグ クラウドに関するより関連性の高いコンテンツについては、123WORDPRESS.COM の過去の記事を検索するか、以下の関連記事を引き続き参照してください。今後とも 123WORDPRESS.COM をよろしくお願いいたします。 以下もご興味があるかもしれません:
|
<<: DockerにMySQL 8.0をインストールする方法
>>: MySQL 最適化技術における Limit クエリの最適化分析
時は経つのが早く、わずか 6 日後には 2013 年が歴史になります。今年は、いわゆるトレンドが多す...
フレーム ウィンドウの関連付けを実現するには、次に示すように、ハイパーリンクの「ターゲット」ウィンド...
まず効果を見てみましょう: 序文:このアイデアは、Bilibili のアップロード者 Steven ...
MYSQL におけるグループ化とリンクは、データベースの操作やデータのやり取りで最もよく使用される ...
ウェブページを作成するときに、フォームを挿入した後、フォームの上下に空白行が表示されることがよくあり...
この記事では、MySQL 8.0.16 winx64のインストールと設定の具体的な方法を記載します。...
レンダリング コード - 青と黄色のリングを例に挙げます <div class="コ...
接続は、実際の外部キー(人工的に作成された 2 つのテーブル間の対応関係を指します。対照的に、FOR...
序文みなさんこんにちは。CSS ウィザードの alphardex です。以前、海外のウェブサイトを閲...
では、早速レンダリングを見てみましょう。 コア コードはtransition: cubic-bezi...
序文仕事では、毎週従業員が提出した資料を数える必要がありますが、それを一つずつコピーして貼り付けるの...
目次Vue2 ライティングVue3プラグインのバージョンの記述Vue3 動的コンポーネントの記述書き...
Linux での MySQL データベースのマスター/スレーブ同期構成の利点は、この方法をバックアッ...
序文誰もが vue2 の watch API に精通している必要があります。vue2 の vue イ...
コードをコピーコードは次のとおりです。 <div id="名前"> ...