jquery实现烟花效果(面向对象)
网络编程 2021-07-04 15:02www.168986.cn编程入门
这篇文章主要为大家详细介绍了jquery面向对象实现烟花效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了jquery实现烟花效果的具体代码,供大家参考,具体内容如下
<!DOCTYPE> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>烟花效果(面向对象)</title> <style type="text/css"> {padding: 0;margin: 0} body{overflow: hidden;width: 100%;height: 100%;background: #000; } div{position: absolute;background: #000;color: #fff} </style> <script src="jquery-1.8.3.min.js"></script></script> </head> <body> <script type="text/javascript"> var firWorks = { init : function(){ //初始化 var _that = this; $(document).bind("click",function(e){ _that.eventLeft = e.pageX; _that.eventTop = e.pageY; _that.createCylinder(); }); }, createCylinder : function(event){ //创建一个花筒 var _that = this; this.cHeight = document.documentElement.clientHeight;//浏览器高度 this.cylinder = $("<div/>"); $("body").append(this.cylinder); this.cylinder.css({"width":4,"height":15,"background-color":"red","":this.cHeight,"left":this.eventLeft}); this.cylinder.animate({:this.eventTop},600,function(){ $(this).remove(); _that.createFlower(); }) }, createFlower : function(){ //创建很多很多的烟花哇!! /烟花效果 1.烟花是很多个DIV构成 2.每个烟花的颜色不一样 3.烟花的位置也不一样 4.烟花散开方向不一样 5.烟花有下坠感觉 / //通过循环可以创建你想要的烟花啦!!! var _that = this; for(var i = 0 ; i < 30; i++ ){ $("body").append($("<div class='flower'></div>")); }; $(".flower").css({"width":3,"height":3,"":this.eventTop,"left":this.eventLeft}); $(".flower").each(function(index, element) { var $this = $(this); var yhX = Math.random()400-200; var yhY = Math.random()600-300; _that.changeColor(); $this.css({"background-color":"#"+_that.randomColor,"width":3,"height":3}).animate({"":_that.eventTop-yhY,"left":_that.eventLeft-yhX},500);//散开 for(var i=0;i<30;i++){ //判断鼠标点击时的右边烟花还是左边烟花 if(yhX<0){ _that.downPw($this,"+");//右下坠 }else{ _that.downPw($this,"-");//左下坠 } } }); }, changeColor : function(){ /烟花的颜色是随机的,而且是用16进制表示色值,所以用随机数结合16进制; 16进制的最大值ffffff,转换成十进制16777215; Math.random()16777215公式可以得到0-16777215之间的数,因为是小数,所以要用到取整; Math.ceil(Math.random()16777215)生成一个在颜色值范围内的,随机的十进制值; Math.random()9+1公式可以得到1-10之间的数,以此类推 .toString(16)方法,是把得到的十进制,转换成16进制,也就是随机的颜色值了; / this.randomColor = ""; this.randomColor = Math.ceil(Math.random()16777215).toString(16)//; //当这个产生的随机的颜色值,不足6位数的进候,需要补齐,又不改变其值,所以要在这个数的前面加零; while(this.randomColor.length<6){ this.randomColor = "0"+this.randomColor; } }, downPw : function(ele,type){ //烟花下坠啦 !!!! ele.animate({"":"+=30","left":type+"=4"},50,function(){ setTimeout(function(){ele.remove()},2000); }) } }; firWorks.init(); </script> </body> </html>
更多JavaScript精彩特效分享给大家
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。
上一篇:微信小程序获取公众号文章列表及显示文章的示
下一篇:非常漂亮的js烟花效果
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指