为什么我的门和灯同时打开呢?用了Deferred,then,不应该是先开门, 后开灯的嘛?
var swipe=new Swipe($(".content"));
var boy=new BoyWalk();
var c=$(".content");
var b={
element: $(".b_background"),
dark:function(){
this.element.removeClass("lamp-bright");
},
bright:function(){
this.element.addClass("lamp-bright");
}
};
function doorAction(l,r,t){
var d=$.Deferred();
var count = 2;
var complete = function() {
if (count == 1) {
d.resolve();
return;
}
count--;
};
$(".door-left").transition({
'left': l
}, t,complete());
$(".door-right").transition({
'left': r
}, t,complete());
return d;
}
$("button:first").click(function(){
doorAction('-50%', '100%', 2000).then(function(){
b.bright();
});
});
$("button:last").click(function(){
doorAction('0%', '50%', 2000).then(function(){
b.dark();
});
});