canvas 魔兽技能冷却效果


*{
margin:0px;
padding:0px;
}

#skills ul,#skills li{
list-style-type:none;
margin:0px;
padding:0px;
}

#skills li{
float:left;
margin-left:5px;
position:relative;
}
#skills canvas.skill{
float:left;
position:absolute;
top:0px;
left:0px;
cursor:pointer;
overflow:hidden;
}

<div id="skills">
<ul>
<li><img src="/img/skillImg/Ability_DualWield.jpg" width=64 height=64 />
<canvas class="skill" width=64 height=64 ></canvas>
</li>
<li><img src="/img/skillImg/Ability_Ensnare.jpg" width=64 height=64 />
<canvas class="skill" width=64 height=64 ></canvas>
</li>
<li><img src="/img/skillImg/Ability_Defend.jpg" width=64 height=64 />
<canvas class="skill" width=64 height=64 ></canvas>
</li>
</ul>
</div>


function init(){
var skills = document.getElementById('skills');
skills.addEventListener('click',function(e){
if(e.target.tagName.toUpperCase() == 'CANVAS'){
paint.call(e.target);
}
},false);
}
function paint(){

if(typeof this.getContext != 'undefined'){
if(this.active)
return;
this.active = true;

var context = this.getContext("2d");
var canvasWidth = this.width,
canvasHeight = this.height,
cx = canvasWidth/2,
cy = canvasHeight/2;


//画一个半透明的灰色背景
context.beginPath();
context.clearRect(0,0,canvasWidth,canvasHeight);
context.moveTo(0,0);
context.fillStyle = 'rgba(0,0,0,.7)';
context.fillRect(0,0,canvasWidth,canvasHeight);
context.fill();


var speed = 100,
step = Math.PI/90,
start = 3*Math.PI/2,
begin = start,
end = start + step,
len = this.width > this.height ? this.width:this.height,
r = Math.round(0.8*len);
if(this.getAttribute('sec')){
speed = Math.round(50*this.getAttribute('sec')/9);
}

context.beginPath();
context.moveTo(cx, cy);
context.fillStyle = 'rgb(0,0,0)';
context.globalCompositeOperation = "destination-out";
var that = this;

var timer = null;
var doPaint = function(){
context.arc(cx, cy, r, start, end, false);
context.fill();
start = end;
end = end + step;
if(end - begin > 2*Math.PI){
clearTimeout(timer);
context.globalCompositeOperation = "source-over";
that.active = null;
return;
}
else
timer = setTimeout(doPaint,speed);

}
doPaint();

}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值