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 クエリの最適化分析

推薦する

MySQLの浅いエントリと深いエグジットの原則についての簡単な説明

目次1. ページの概要2. 下限と上限3. ページディレクトリを使用する4. ページの実際の外観4....

Tencent Cloudでhive3.1.2を構築する方法を教えます

環境の準備操作を開始する前に、hadoop バージョンがインストールされていることを確認してください...

JavaScript 関数をよりエレガントにする方法

目次分割代入を使用したオブジェクトパラメータコールバック関数の命名条件文を説明的にするスイッチ文をM...

Vue でコンポーネントを一括インポート、登録、使用する方法

序文コンポーネントは、非常に頻繁に使用されるものです。多くの人は、コンポーネントを 1 つのファイル...

ドラッグアンドドロップでVueユーザーインターフェースを生成する方法

目次序文1. 技術原理1.1 レイアウト1.2 コンポーネント1.3 ステータス1.4 イベント1....

CSS3 で複数のカスタムフォントを導入する

今日、HTML に問題を発見しました。多くのデフォルト フォントが提供されていますが、「Bold」、...

nginxのデフォルトポートを変更する方法の詳細な説明

まず設定ファイルがどこにあるか調べる nginx.confはどこにありますかこれらのディレクトリを調...

MySQL 空間データストレージと関数

目次1. データ型1. MySQL空間データとは何か2. GeoJSONとは3. 空間データ型のフォ...

リモートログインとポート公開を防ぐためのLinuxサーバー構成IPホワイトリスト

序文ブロガーが使用しているサーバーは Alibaba Cloud から購入したものです。実際、Ali...

すべてのウェブ開発者が知っておくべき61のこと

通常、全員のスピーチを最初から最後まで読む必要があります。ただし、Stack Overflow には...

MySQL カウントを向上させる方法のまとめ

多くのプログラマーは MySQL に精通していると思います。多くの人が count の使い方と、最適...

IIS7 IIS8 http は自動的に HTTPS にジャンプします (ポート 80 はポート 443 にジャンプします)

IIS7 では、「URL REWRITE2」疑似静的モジュールがインストールされているかどうかを確...

Linux ターミナルでドメイン IP アドレスを見つけるコマンド (5 つの方法)

このチュートリアルでは、Linux ターミナルでドメイン名またはコンピューター名の IP アドレスを...

jsはaudioContextを通じて3Dサウンド効果を実現します

この記事では、audioContextを介して3Dサウンド効果を実現するためのjsの具体的なコードを...

VMWare仮想マシンにCentOS7システムをインストールする詳細な手順

インストール前の作業: VMware Workstation がインストールされていることを確認し、...