没有合适的资源?快使用搜索试试~ 我知道了~
想要学会这个漂亮的烟花吗?快来跟着学习吧~ 结构 我们只需要一个盒子表示烟花爆炸范围就可以了 样式 fire是烟花 注意添加绝对定位 .container{ margin: 0 auto; height: 500px; width: 1200px; background: black; position: relative; overflow: hidden; } .fire{ width: 10px; background: whit
资源详情
资源评论
资源推荐
教你用面向对象编程写一个烟花爆炸的特效教你用面向对象编程写一个烟花爆炸的特效
想要学会这个漂亮的烟花吗?快来跟着学习吧~
结构结构
我们只需要一个盒子表示烟花爆炸范围就可以了
样式样式
fire是烟花 注意添加绝对定位
.container{
margin: 0 auto;
height: 500px;
width: 1200px;
background: black;
position: relative;
overflow: hidden;
}
.fire{
width: 10px;
background: white;
height: 10px;
/* border-radius: 50%; */
position: absolute;
bottom: 0;
}
行为行为
编写构造函数编写构造函数Firework
需要用到一个鼠标点击的位置,一个div选择器,一个爆炸样式
function Firework(x,y,selector,type){
//此处获取对象的方式为单例的思想,避免重复获取相同的元素
if(Firework.box && selector === Firework.box.selector){
this.box = Firework.box.ele;
}else{
Firework.box = {
ele:document.querySelector(selector),
selector:selector
}
this.box = Firework.box.ele;
}
this.type = type;
this.init(x,y)
}
封装一个运动的方法封装一个运动的方法
function animation(ele,attroptions,callback){
for(var attr in attroptions){
attroptions[attr] ={
target:attroptions[attr],
inow:parseInt(getComputedStyle(ele)[attr])
}
}
clearInterval(ele.timer);
ele.timer = setInterval(function(){
for(var attr in attroptions ){
var item = attroptions[attr] var target = item.target;
var inow = item.inow;
var speed = (target - inow)/10;
speed = speed>0?Math.ceil(speed):Math.floor(speed);
if(Math.abs(target - inow) <= Math.abs(speed)){
ele.style[attr] = target+"px";
delete attroptions[attr];
for(var num in attroptions){
return false;
}
clearTimeout(ele.timer);
if(typeof callback === "function")callback();
}else{
weixin_38625416
- 粉丝: 4
- 资源: 920
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0