国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

【用三大件寫出的開門煙花特效】

這篇具有很好參考價值的文章主要介紹了【用三大件寫出的開門煙花特效】。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

又到了一年一度的春節(jié)時期啦!昨天呢是北方的小年,今天是南方的小年,看到大家可以愉快的放煙花,過大年很是羨慕呀!辭舊歲,賀新春,今年我呀要放煙花,過春節(jié)!??。

這個特效簡單的使用了前端三件套即可完成,html,js,css,canvas整體效果如下GIF圖所示(碼內(nèi)隱藏特殊變量,找到有驚喜?。?/p>

前端開門特效,前端,html,javascript,Powered by 金山文檔
背景音樂是《China-E》個人感覺很有新年的感覺,整個China系列的歌曲都很nice,該特效的寓意就是開門大吉,辭舊迎新,2023年的大門向你敞開,新的一年想你招手,小兔子抱著錦鯉,也預(yù)示著吉祥,山魚在這里祝大家前兔無量,大展宏兔!

就是開心,就是玩,就是兔個吉利!,話不多說上代碼!

<body>
    <!-- 依舊是簡潔的html代碼 -->
    <canvas id="mycanvas"></canvas>

    <div id="box">
        <button type="button" id="unmuteButton">開啟新年音樂</button>
        <button type="button" id="unmuteButton2">關(guān)閉新年音樂</button>
        <video id="video" muted autoplay src="./audio/新年音樂.mp3" loop></video>
    </div>
</body>

比較多的css代碼,所以單獨放在了一個文件下,如果用的時候出現(xiàn)圖片丟失的問題,可以看看路徑寫對了沒

/* 如果單獨放記得去掉style標(biāo)簽哦 */
<style>
* {
    margin: 0;
    padding: 0;
}

body {
    overflow: hidden;
    margin: 0;
    cursor: pointer;
    font-size: 30px;
    background: url("../img/辭舊歲賀新春兔年.png");
    background-size: 100% 100%;
}

#unmuteButton {
    position: absolute;
    z-index: -1;
    top: 0;
    left: 0;
    font-size: 10px;
    font-family: "STHupo";
    width: 80px;
    height: 30px;
    border: 1px solid red;
    background-color: rgb(255, 115, 0);
    border-radius: 10%;
}

#unmuteButton2 {
    position: absolute;
    z-index: -1;
    top: 0px;
    left: 120px;
    font-size: 10px;
    font-family: "STHupo";
    width: 80px;
    height: 30px;
    border: 1px solid red;
    background-color: rgb(255, 115, 0);
    border-radius: 10%;
}

#video {
    position: absolute;
    top: -100000;
    left: -100000;
}

#box {
    position: absolute;
    z-index: 1;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
}

#box::before,
#box::after {
    content: '';
    z-index: 99;
    margin-top: -37px;
    float: left;
    width: 50%;
    height: 1000px;
    background: url("../img/兔子2023.png") no-repeat;
    transition: .4s;
}

#box::before {
    float: left;
    background-position: -220px 37px;
}

#box::after {
    float: right;
    background-position: -210px;
}

#box:hover::before {
    transform: translateX(-100%)
}

#box:hover::after {
    transform: translateX(100%)
}

/* 去除滾動條 */
body::-webkit-scrollbar {
    width: 0 !important
}
</style>

比比比比較多的js代碼,注意同上文章來源地址http://www.zghlxwxcb.cn/news/detail-811983.html

// 煙花生成
window.requestAnimationFrame = (function () {
    return window.requestAnimationFrame ||
        window.webkitRequestAnimationFrame ||
        window.mozRequestAnimationFrame ||
        function (callback) {
            window.setTimeout(callback, 1000)
        }
})();
// 獲取畫布
var area = document.getElementById("mycanvas");
area.width = document.documentElement.clientWidth;
area.height = document.documentElement.clientHeight;

var ctx = area.getContext("2d");

hue = 120;
timerTick = 0;
timerTotal = 5;
fireworks = [];
particles = [];

function random(min, max) {
    return Math.random() * (max - min) + min;
}

function distans(sx, sy, tx, ty) {
    var xdistan = sx - tx;
    var ydistan = sy - ty;
    return Math.sqrt((Math.pow(xdistan, 2) + Math.pow(ydistan, 2)));
}

function Firework(sx, sy, tx, ty) {
    this.x = sx;
    this.y = sy;
    this.sx = sx;
    this.sy = sy;
    this.tx = tx;
    this.ty = ty;

    this.targetDistances = distans(sx, sy, tx, ty);

    this.distancesc = 0;

    this.shanyu = [];
    this.shanyucount = 3;
    while (this.shanyucount--) {
        this.shanyu.push([this.x, this.y]);
    }

    this.angle = Math.atan2(ty - sy, tx - sx);
    this.speed = 2;
    this.jiasudu = 1.05;
    this.brightness = random(50, 70);
    this.targetRad = 5;
}

Firework.prototype.update = function (index) {
    this.shanyu.pop();
    this.shanyu.push([this.x, this.y]);

    if (this.targetRad < 8) {
        this.targetRad += 0.3;
    } else {
        this.targetRad = 1;
    }

    this.speed *= this.jiasudu;
    var vx = Math.cos(this.angle) * this.speed;
    var vy = Math.sin(this.angle) * this.speed;

    this.distancesc = distans(this.sx, this.sy, this.x + vx, this.y + vy);

    if (this.distancesc >= this.targetDistances) {

        createparticals(this.tx, this.ty);

        fireworks.splice(index, 1)
    } else {
        this.x += vx;
        this.y += vy;
    }
}


Firework.prototype.draw = function () {
    ctx.beginPath();

    ctx.moveTo(this.shanyu[this.shanyu.length - 1][0], this.shanyu[this.shanyu.length - 1][1]);

    ctx.lineTo(this.x, this.y);

    ctx.strokeStyle = 'hsl(' + hue + ',100%,' + this.brightness + '%)';
    ctx.stroke();

    ctx.beginPath();
    ctx.arc(this.tx, this.ty, this.targetRad, 0, Math.PI * 2);
    ctx.stroke();
}

function Particle(x, y) {
    this.x = x;
    this.y = y;
    this.shanyu = [];
    this.shanyucount = 10;
    while (this.shanyucount--) {
        this.shanyu.push([this.x, this.y]);
    }

    this.angle = random(0, 2 * Math.PI);
    this.speed = random(1, 10);
    this.mocal = 0.95;
    this.gravity = 0.98;
    this.hue = random(hue - 20, hue + 20);
    this.brightness = random(50, 80);
    this.alpha = 1;
    this.decay = random(0.015, 0.03);
}

Particle.prototype.update = function (index) {
    this.shanyu.pop();
    this.shanyu.unshift([this.x, this.y]);
    this.speed *= this.mocal;
    this.x += Math.cos(this.angle) * this.speed;
    this.y += Math.sin(this.angle) * this.speed + this.gravity;
    this.alpha -= this.decay;
    if (this.alpha <= this.decay) {
        particles.splice(index, 1)
    }
}
Particle.prototype.draw = function () {
    ctx.beginPath();
    ctx.moveTo(this.shanyu[this.shanyu.length - 1][0], this.shanyu[this.shanyu.length - 1][1]);
    ctx.lineTo(this.x, this.y);
    ctx.strokeStyle = 'hsl(' + hue + ',100%,' + this.brightness + '%)';
    ctx.stroke();
}

function createparticals(x, y) {
    var particalcount = 500;
    while (particalcount--) {
        particles.push(new Particle(x, y))
    }
}

var clientw = document.documentElement.clientWidth;
var clienth = document.documentElement.clientHeight;

function loop() {
    requestAnimationFrame(loop);
    hue += 0.5;
    ctx.globalCompositeOperation = 'destination-out';
    ctx.fillRect(0, 0, clientw, clienth);
    ctx.fillStyle = 'rgb(0,0,0,0.5)';
    ctx.globalCompositeOperation = 'lighter';
    var i = fireworks.length;
    while (i--) {
        fireworks[i].draw();
        fireworks[i].update(i);
    }
    var i = particles.length;
    while (i--) {
        particles[i].draw();
        particles[i].update(i);
    }
    if (timerTick >= timerTotal) {
        fireworks.push(new Firework(clientw / 2, clienth, random(0, clientw), random(0, clienth)));
        timerTick = 0;
    } else {
        timerTick++;
    }
}
window.οnlοad = loop();
window.onload = function starttime() {
    ptimer = setTimeout(starttime, 1000);
}
// 音樂控制
unmuteButton.addEventListener('click', function () {
    video.muted = false;
});
unmuteButton2.addEventListener('click', function () {
    video.muted = true;
});
結(jié)束嘍,下一篇新春特效就是下一年嘍!
點贊:您的贊賞是我前進(jìn)的動力! ??
收藏:您的支持我是創(chuàng)作的源泉! ?
評論:您的建議是我改進(jìn)的良藥! ?
山魚的個人社區(qū):歡迎大家加入我的個人社區(qū)—— 山魚社區(qū)

到了這里,關(guān)于【用三大件寫出的開門煙花特效】的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • ??創(chuàng)意網(wǎng)頁:制作一個絢麗的煙花效果(HTML、CSS和JavaScript實現(xiàn))

    ??創(chuàng)意網(wǎng)頁:制作一個絢麗的煙花效果(HTML、CSS和JavaScript實現(xiàn))

    ? 博主: 命運之光 ?? 專欄: Python星辰秘典 ?? 專欄: web開發(fā)(簡單好用又好看) ?? 專欄: Java經(jīng)典程序設(shè)計 ?? 博主的其他文章: 點擊進(jìn)入博主的主頁 前言: 歡迎踏入我的Web項目專欄,一段神奇而令人陶醉的數(shù)字世界! ?? 在這里,我將帶您穿越時空,揭開屬于

    2024年02月17日
    瀏覽(30)
  • HTML JavaScript 數(shù)字變化特效

    HTML JavaScript 數(shù)字變化特效

    案例一:上下滾動 案例二:本身變化

    2024年01月22日
    瀏覽(19)
  • 超好看的前端特效HTML特效、CSS特效、JS特效(第一期)

    超好看的前端特效HTML特效、CSS特效、JS特效(第一期)

    1. 粒子組成文字動畫特效 文件組成: base.css demo.css bcg.jpg demo.js demo.scss index.html 2. 愛心表白特效 文件組成: heart.svg index.html 3. 愛心跟隨鼠標(biāo) index.html 4. 滿屏漂浮愛心 index.html 5. 黑客帝國矩陣雨 index.html 6. 2024新年快樂動畫特效 文件目錄: style.css script.js index.html 7. 表白特效

    2024年02月19日
    瀏覽(20)
  • html、css、javascript簡單三劍客實現(xiàn)櫻花飄落\雪花飄落特效匯總

    html、css、javascript簡單三劍客實現(xiàn)櫻花飄落\雪花飄落特效匯總

    素材來源于網(wǎng)絡(luò)稍作修改 侵刪 如果覺得復(fù)制下面運行有問題或者嫌麻煩 可以直接下載源代碼 歡迎fork、star 預(yù)覽 話不多說,直接上代碼 預(yù)覽 預(yù)覽

    2024年02月14日
    瀏覽(98)
  • Python煙花代碼,用Python制作一個煙花特效

    Python煙花代碼,用Python制作一個煙花特效

    Python實現(xiàn)浪漫的煙花特效 現(xiàn)在很多地方都不能放煙花了,既然看不到, 那作為程序猿的我們還不能自己用代碼做一個嗎? 今天就帶大家用代碼做一個煙花特效吧。 pygame介紹 關(guān)于Pygame的基本信息,pygame是什么,誰會被Pygame吸引,并且在哪里找到它。 Pygame是被設(shè)計用來寫游戲

    2024年02月08日
    瀏覽(25)
  • 前端酷炫合集--HTML做一個三維脈沖特效
  • Unity煙花特效實現(xiàn)(附源碼)

    Unity煙花特效實現(xiàn)(附源碼)

    朋友過生,不知道送什么禮物,就想著用自己所學(xué)知識做個特效當(dāng)禮物吧,嘿。 主要參考了 這位up的視頻 ,感謝 https://github.com/hahahappyboy/UnityProjects/tree/main/%E7%83%9F%E8%8A%B1(%E7%B2%92%E5%AD%90%E7%B3%BB%E7%BB%9F) 主要就是1個主煙花粒子系統(tǒng)帶3個子粒子系統(tǒng),這三個小的粒子系統(tǒng)分別是拖

    2024年02月08日
    瀏覽(66)
  • 〖大前端 - 基礎(chǔ)入門三大核心之JS篇?〗- JavaScript 的「數(shù)組」

    〖大前端 - 基礎(chǔ)入門三大核心之JS篇?〗- JavaScript 的「數(shù)組」

    當(dāng)前子專欄 基礎(chǔ)入門三大核心篇 是免費開放階段 。 推薦他人訂閱,可獲取扣除平臺費用后的35%收益,文末名片加V! 說明:該文屬于 大前端全棧架構(gòu)白寶書專欄, 目前階段免費開放 , 購買任意白寶書體系化專欄可加入 TFS-CLUB 私域社區(qū)。 福利:除了通過訂閱\\\"白寶書系列專

    2024年02月04日
    瀏覽(23)
  • python和pygame實現(xiàn)煙花特效

    python和pygame實現(xiàn)煙花特效

    新年來臨之際,來一個歡慶新年煙花祝賀,需要安裝使用第三方庫pygame,關(guān)于Python中pygame游戲模塊的安裝使用可見 https://blog.csdn.net/cnds123/article/details/119514520 效果圖及源碼 先看效果圖: 源碼如下: pygame在屏幕上顯示字體的方法說明 使用 pygame.font.Font 函數(shù)來設(shè)置字體和大小,

    2024年02月04日
    瀏覽(28)
  • 前端:運用html+css+js模仿京東上商品圖片區(qū)域放大特效

    前端:運用html+css+js模仿京東上商品圖片區(qū)域放大特效

    1. 前言 最近在網(wǎng)頁端瀏覽京東上的商品時,覺得上面的那張gif圖片上實現(xiàn)的特效不錯,于是自己打算使用html+css+js技術(shù)來實現(xiàn)一下上述特效效果,我的實效果如下: 2. 前端界面 主要使用到浮動、絕對定位、相對定位等知識,不了解這部分知識點的讀者可以先去了解了解,再

    2024年02月16日
    瀏覽(40)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包