下雪效果

来源:https://www.cnblogs.com/xiaoyaolang/archive/2019/11/25/11927438.html
-Advertisement-
Play Games

下雪效果 1 <style> 2 * { 3 margin: 0; 4 padding: 0; 5 } 6 #box { 7 width: 1000px; 8 height: 600px; 9 background: #000000; 10 border: 5px solid red; 11 mar ...


下雪效果

 1 <style>
 2     * {
 3         margin: 0;
 4         padding: 0;
 5     }
 6     #box {
 7         width: 1000px;
 8         height: 600px;
 9         background: #000000;
10         border: 5px solid red;
11         margin: 20px auto;
12         position: relative;
13     }
14     img{
15         position: absolute;
16     }
17 </style>
18 
19 <body>
20     <div id="box"></div>
21 </body>
22 </html>
23 <script src="public.js"></script>
24 <script>
25     /*
26          分析構造函數   Snow
27          屬性 : img   box
28          方法 :  雪花創建init   移動
29     */
30     window.onload = function(){
31         setInterval( function(){
32             new Snow().init().move();
33         },800 )
34     }
35     function Snow(){
36         this.img = document.createElement("img");
37         this.box = $id("box");
38         this.init = function(){//雪花創建
39             this.img.src = "img/snow.png";
40             this.box.appendChild( this.img );
41             this.img.width=this.img.height = rand(10,15);
42             this.img.style.left = rand(0,this.box.offsetWidth-this.img.offsetWidth) + "px";
43             this.img.style.top = -this.img.offsetHeight+"px";
44             return this;
45         }
46         this.move = function(){
47             //定義雪花移動的速度
48             var speedX = -rand(1,5);
49             var speedY = rand(1,5);
50             this.timer = setInterval( function(){
51                 this.img.style.left = this.img.offsetLeft +  speedX + "px";
52                 this.img.style.top = this.img.offsetTop + speedY + "px";
53                 if( this.img.offsetLeft < -this.img.offsetWidth || this.img.offsetTop > this.box.offsetHeight ){
54                     //clearInterval( this.timer );
55                     this.img.remove();
56                 }
57             }.bind(this),30 )
58         }
59     }
60 </script>

public.js

function $id(id){//給我一個id名,返回一個這個id的元素
    return document.getElementById(id);
}
//求隨機數
function rand(min,max){
    return Math.round(Math.random()*(max - min) + min);
}

//隨機的16進位顏色
function getColor(){
    var str = "0123456789ABCDEF";//十六進位字元串
    var color = "#";
    for(var i = 0; i <= 5; i++){//取6個數
        color += str.charAt(rand(0,15));
        //rand(0,15)隨機0-15之間的數,作為charAt()的下標,取出下標對應的字元
    }
    return color;
}
function zero(val){
    return val < 10 ? "0" + val : val;
}
//時間差
function diff(start,end){//2000-2018  2018 - 2000
    //console.log(start.getTime());
    return Math.abs(start.getTime() - end.getTime())/1000;
}
View Code

雪花圖片(下方)


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 背景 一開始買完伺服器裝的是用apache搭的後臺, 現在想使用nginx, 希望對你有參考作用 查看系統版本信息 我的版本信息是 首先關閉apache tomcat服務 最穩妥的關閉方法,找到你的安裝路徑,執行bin下的shutdown腳本 要開啟執行startup腳本 安裝nginx yum i ...
  • //console.log('每隔*秒鐘刷新一次'); var timer = window.setInterval(function() { $("#table_list_1").trigger("reloadGrid"); },10 * 1000); ...
  • /** * 依賴文件sockjs.js、stomp.js * */ ;!(function (window) { 'use strict' let WS = function () { //保存所有的訂閱事件 {Aevent:[pubfun(status,data),pubfun(status,da ...
  • 排他思想: 點擊其中一個時其他的變,就自己不變 如圖: html和css代碼 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 </head> 7 <body ...
  • 原來 實際上這段代碼等同於 而如果代碼會如下寫法則a方法會執行 ...
  • 小圖展示大圖 1 <style> 2 *{margin:0;padding:0;} 3 ul,ol{list-style:none;} 4 #box { 5 position:relative; 6 margin:100px auto; 7 border:1px solid #ccc; 8 widt ...
  • 自引jquery 1 <style> 2 * { margin: 0; padding: 0; } 3 ul { list-style: none; margin: 100px; } 4 .comment { 5 color: red; 6 } 7 8 .comment li { 9 float: ...
  • 螢火蟲 <style type="text/css"> *{ padding: 0; margin: 0; } #bg{ background: url(img/bg.jpg) no-repeat; background-size: cover; width: 100%; height: 100%; ...
一周排行
    -Advertisement-
    Play Games
  • Dapr Outbox 是1.12中的功能。 本文只介紹Dapr Outbox 執行流程,Dapr Outbox基本用法請閱讀官方文檔 。本文中appID=order-processor,topic=orders 本文前提知識:熟悉Dapr狀態管理、Dapr發佈訂閱和Outbox 模式。 Outbo ...
  • 引言 在前幾章我們深度講解了單元測試和集成測試的基礎知識,這一章我們來講解一下代碼覆蓋率,代碼覆蓋率是單元測試運行的度量值,覆蓋率通常以百分比表示,用於衡量代碼被測試覆蓋的程度,幫助開發人員評估測試用例的質量和代碼的健壯性。常見的覆蓋率包括語句覆蓋率(Line Coverage)、分支覆蓋率(Bra ...
  • 前言 本文介紹瞭如何使用S7.NET庫實現對西門子PLC DB塊數據的讀寫,記錄了使用電腦模擬,模擬PLC,自至完成測試的詳細流程,並重點介紹了在這個過程中的易錯點,供參考。 用到的軟體: 1.Windows環境下鏈路層網路訪問的行業標準工具(WinPcap_4_1_3.exe)下載鏈接:http ...
  • 從依賴倒置原則(Dependency Inversion Principle, DIP)到控制反轉(Inversion of Control, IoC)再到依賴註入(Dependency Injection, DI)的演進過程,我們可以理解為一種逐步抽象和解耦的設計思想。這種思想在C#等面向對象的編 ...
  • 關於Python中的私有屬性和私有方法 Python對於類的成員沒有嚴格的訪問控制限制,這與其他面相對對象語言有區別。關於私有屬性和私有方法,有如下要點: 1、通常我們約定,兩個下劃線開頭的屬性是私有的(private)。其他為公共的(public); 2、類內部可以訪問私有屬性(方法); 3、類外 ...
  • C++ 訪問說明符 訪問說明符是 C++ 中控制類成員(屬性和方法)可訪問性的關鍵字。它們用於封裝類數據並保護其免受意外修改或濫用。 三種訪問說明符: public:允許從類外部的任何地方訪問成員。 private:僅允許在類內部訪問成員。 protected:允許在類內部及其派生類中訪問成員。 示 ...
  • 寫這個隨筆說一下C++的static_cast和dynamic_cast用在子類與父類的指針轉換時的一些事宜。首先,【static_cast,dynamic_cast】【父類指針,子類指針】,兩兩一組,共有4種組合:用 static_cast 父類轉子類、用 static_cast 子類轉父類、使用 ...
  • /******************************************************************************************************** * * * 設計雙向鏈表的介面 * * * * Copyright (c) 2023-2 ...
  • 相信接觸過spring做開發的小伙伴們一定使用過@ComponentScan註解 @ComponentScan("com.wangm.lifecycle") public class AppConfig { } @ComponentScan指定basePackage,將包下的類按照一定規則註冊成Be ...
  • 操作系統 :CentOS 7.6_x64 opensips版本: 2.4.9 python版本:2.7.5 python作為腳本語言,使用起來很方便,查了下opensips的文檔,支持使用python腳本寫邏輯代碼。今天整理下CentOS7環境下opensips2.4.9的python模塊筆記及使用 ...