★JavaScript礼花特效★

一款不错的礼花特效,把背景色改成黑色效果更好。

<style type="text/css">
    .ball{color:#FF0000; position:absolute; font-size:16px;}
    .star{color:#FF0000; position:absolute; font-size:4px;}
</style>
<script type="text/javascript">
function Fireworks(sky, loop){
    this.sky = sky;
    this.skyWidth = document.body.clientWidth || document.documentElement.clientWidth;
    this.skyHeight= document.body.clientHeight || document.documentElement.clientHeight;
    this.x = this.y = 0;
    this.step = 20;
    this.delay = 30;
    this.stars = [];
    this.r = 10;
    this.step2 = 7;
    this.radius = 90;
    this.angle = 45;
    this.num = 16;
    this.loop = loop;
    this.degree = 2;
    this.t = 0;
    this.delt = 0;
    this.max = 30;
    this.cur = 1;
    this.points = null;
}
Fireworks.prototype = {
    init : function(){
        this.x = parseInt(this.skyWidth/1.3 * Math.random()) + this.skyWidth / 8;
        this.y = this.skyHeight;
        this._y = parseInt((this.skyHeight / 4) * Math.random()) + this.skyHeight / 5;
    },
    setOpacity : function(obj, p){
        if(p > 85){
            var opacity = 100 - (p - 85) * 4;
            if(document.all){
                obj.style.filter = "alpha(opacity=" + opacity + ")";    
            }else{
                obj.style.MozOpacity = opacity / 100;
            }
        }
    },
    getNextPoint : function(degree, coeff, t){
        var tt = 1.0 - t;
        for(var rr = 1; rr <= degree; rr++){
            for(var i=0; i <= degree-rr; i++){
                coeff[i] = tt * coeff[i] + t * coeff[i+1];
            }
        }
        return coeff[0];
    },
    showBall : function(){
        this.ball = document.createElement("div");
        this.ball.innerHTML = "●";
        this.ball.className = "ball";
        this.ball.style.left = this.x + "px";
        this.ball.style.top = this.y + "px";
        this.sky.appendChild(this.ball);
    },
    moveBall : function(){
        var self = this;
        if(this.y > this._y){
            var p = parseInt((this.skyHeight - this.y) / (this.skyHeight - this._y)*10);
            this.y -= (this.step - p * 1.6);
            this.ball.style.fontSize = 16 - p + "px";
            this.ball.style.top = this.y + "px";
            setTimeout(function(){self.moveBall();}, this.delay);
        }else{
            this.fire();
        }
    },
    hideBall : function(){
        this.sky.removeChild(this.ball);
        this.ball = null;
    },

    showStars : function(){
        var colors = [’#FF0000’,’#FF00FF’,’#00FF00’,’#00FFFF’,’#FFFF00’,’#FF0000’,’#FF00FF’,’#00FF00’,’#00FFFF’,’#FFFF00’];
        var n = cs = parseInt(Math.random() * colors.length / 2);
        var cc = parseInt(Math.random() * colors.length  / 2);
        var colorMode = parseInt(Math.random() * 2);
        var star = Math.round(Math.random()) == 1 ? "★" : "☆";
        this.r = 10;
        this.radius = Math.round(Math.random() * 30) + 60;
        this.num = Math.round(Math.random() * 5 + 5) * 2;
        this.angle = 180 / this.num * 2;
        
        for(var i=1; i<=this.num; i++){
            this.stars[i] = document.createElement("div");
            this.stars[i].innerHTML = star;
            this.stars[i].className = "star";
            if(colorMode == 1){
                this.stars[i].style.color = colors[n];
                if(++n > cs + cc)
                    n = cs;
            }else{
                this.stars[i].style.color = colors[parseInt(Math.random() * colors.length)];
            }
            this.sky.appendChild(this.stars[i]);
        }
    },
    moveStars : function(){
        var self = this;
        if(this.r < this.radius){
            var p = this.step2 - parseInt(this.r / this.radius * 5);
            p = p < 1 ? 1 : p;
            this.r += p;
            p = parseInt(this.r / this.radius * 100);
            for(var i=1; i<=this.num; i++){
                this.stars[i].style.left = this.x - Math.round(this.r * Math.sin(Math.PI - (Math.PI / 180 * this.angle * i))) + "px";
                this.st

代码演示:

评论

  1. 315返佣网
    2025年前
    -0001-11-30 0:00:00

    说的不错
    那么问题来了
    白银返佣哪家强
    315返佣网找国强
    http://www.315fanyong.com
    http://www.baiyinshijia.com

  2. 。。。
    2025年前
    -0001-11-30 0:00:00

    呵呵

发送评论 编辑评论


|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇