流れ星のアニメーション効果をJSで実現

php中世界最好的语言
リリース: 2018-04-19 10:33:05
オリジナル
2408 人が閲覧しました

今回は流れ星のアニメーション効果を実現するためのJSをお届けします。JSを使用して流れ星のアニメーション効果を実現するための注意事項を紹介します。

<!DOCTYPE html>
<htmllang="en">
<head>
 <metacharset="UTF-8">
 <title>Title</title>
 <style>
  img{
   position: absolute;
  }
  body {
   background-image: url(img/bg.jpg);
   background-size: 100%;
  }
 </style>
 <script>
  function Star() {
   this.speed=10;
   this.img=new Image();
   this.img.src="img/star"+parseInt(Math.random()*4+1)+".png";
   this.img.style.width=50+'px';
   this.img.style.height=50+'px';
   this.img.style.top=Math.random()*window.innerHeight+1+'px';
   this.img.style.left=Math.random()*window.innerWidth+1+'px';
   document.body.appendChild(this.img);
  }
  Star.prototype.slip=function () {
   var that=this;
   function move() {
    that.img.style.top=that.img.offsetTop+that.speed+'px';
    console.log(that.img.offsetTop+"star");
    console.log(window.innerHeight+"window");
    if(that.img.offsetTop>window.innerHeight){
     clearInterval(sh);
     that.img.style.height=0;
     that.img.style.width=0;
    }
   }
   var sh=setInterval(move,100);
  }
   setInterval(function () {
    for(var i=1;i<5;i++){
    new Star().slip();
    }
   },1000)
 </script>
<body>
</body>
</html>
ログイン後にコピー

信 この事例を読んだ後、あなたはすでにその方法をマスターしていると思います。さらに興味深い内容については、PHP 中国語 Web サイトの他の関連記事に注目してください。

推奨読書:

JSはデータ検証とチェックボックスフォームの送信を実装します

vue.jsの双方向バインディングの使用法の詳細な説明

JSはカルーセルチャートを簡単に実装します

以上が流れ星のアニメーション効果をJSで実現の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!