Vue で 3D タグ クラウドを実装するための詳細なコード

Vue で 3D タグ クラウドを実装するための詳細なコード

プレビュー:

コード:
ページセクション:

<テンプレート>
  <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 をよろしくお願いいたします。

以下もご興味があるかもしれません:
  • Vue でタグクラウド効果を実装する例
  • Vueでタグクラウド効果を実装する方法の詳細な説明
  • Vueページでは3Dアニメーションシーン操作を実現するthree.jsを紹介
  • VUE 3Dカルーセルカプセル化実装方法
  • vue.js で 3DES 暗号化を使用する例
  • Vue で highCharts を使用して 3D 円グラフを描く方法

<<:  DockerにMySQL 8.0をインストールする方法

>>:  MySQL 最適化技術における Limit クエリの最適化分析

推薦する

Vue開発ウェブサイトSEO最適化方法の詳細な説明

ページデータの表示には Vue などの js のデータバインディング機構が使用されるため、クローラー...

MySQLインデックスの失敗の典型的なケース

目次典型的なケース付録: 一般的なインデックス障害の状況典型的なケース次の構造を持つ 2 つのテーブ...

ミニプログラムカスタムコンポーネントの非効率的なグローバルスタイルの解決策

目次長すぎて読めないコンポーネントスタイルの分離デモテスト優先度ページの分離構成参考文献ネイティブ ...

ウェブサイトのフロントエンドをエレガントでユーザーにとって魅力的なものにする方法

ウェブフロントエンドのウェブサイトの気質は感情であり、言葉なしでユーザーを魅了できる感情です。では、...

MySQLデータベーステーブルの定期バックアップの実装の詳細な説明

Mysqlデータベーステーブルの定期的なバックアップの実装0. 背景実際の開発環境では、フロントエン...

Vue の v-model ディレクティブと .sync 修飾子の違いの詳細な説明

目次vモデル.sync微妙な違い機能シナリオを要約します。 vモデル <!--親コンポーネント...

MySQL シーケンス AUTO_INCREMENT の詳細な説明とサンプルコード

MySQL シーケンス AUTO_INCREMENT の詳細な説明とサンプルコードMySQL シーケ...

MySQLのあいまいクエリインデックスの失敗の問題を解決するいくつかの方法

% ワイルドカードを使用すると、インデックス失敗の問題が発生することがよくあります。ここでは、lik...

役に立つメタ設定方法(必読)

<meta name="viewport" content="...

デザイン理論:人間中心のデザインコンセプト

<br />思想が東西に分かれていた時代、東洋の叡智を代表するものの一つとして「禅」は多...

Kubernetesでポッドを作成する方法

目次ポッドを作成するには? kubectl ツールポッドを作成するには?前回の記事では、コンテナとポ...

支払いカウントダウンを実現し、ホームページに戻るためのjs

ホーム ページに戻るための支払いカウントダウン ケースの概要: シンプルな js 構文、getEle...

MySQL の innodb_flush_log_at_trx_commit と sync_binlog を区別する方法

2 つのパラメータ innodb_flush_log_at_trx_commit と sync_bi...

Viteプロジェクトを作成する手順

目次序文yarn create は何をしますか?ソースコード分析プロジェクトの依存関係テンプレート構...

プレーンな JS オブジェクトの代わりに Map を使用する場合

目次1. マップは任意のタイプのキーを受け入れます2. マップにはキー名に関する制限はありません3....