var obj = boxStack[i];
obj.style.left=left+‘px’;
obj.style.top=top+‘px’;
obj.style.marginLeft=marginLeft-i*6+‘px’;
obj.style.marginTop=marginTop-i*6+‘px’;
obj.style.zIndex=zIndex+i;
obj.style.width=(width+i*12)+‘px’;
obj.style.height=height+‘px’;
//obj.children[0].style.width=(width+i*12)+‘px’;
//obj.children[0].style.height=height+‘px’;
//每个卡片设置不同的颜色
switch (obj.id) {
case ‘card1’:
obj.style.background = ‘aliceblue’;
break;
case ‘card2’:
obj.style.background = ‘skyblue’;
break;
case ‘card3’:
obj.style.background = ‘powderblue’;
break;
case ‘card4’:
obj.style.background = ‘steelblue’;
break;
}
}
}
//拖动卡片的事件函数
function tran(e){
var e = e || window.event;
var target = e.target || e.srcElement;
console.log(target.id);
if(target.id){
//拖动当前的卡片
move_tran(target);
}
}
//点击box的事件函数
function tranBox(e){
var e = e || window.event;
var target = e.target || e.srcElement;
if(target.id){
if(target.id===‘div_box’){//点击div_box从最上面开始飞
move_tran(boxStack[boxStack.length-1]);
}
}
}
var moveFlag=false;//正在移动表示,有卡片正在移动,move 函数将不会被调用
function move_tran(obj,direction,step){
if(moveFlag) return ;//表示有卡片正在移动,move 函数将不会被调用
if(obj.timer) return ;//避免重复点击
moveFlag=true;//设置当前正在移动
step=step||0;
var cb = (function (){//回调函数
var speed=5;
var screenTotal=0;