0
我写了一个组件。开始时,两个物体(抽屉和输液餐具)的移动是同步的。点击冲泡刀具后,抽屉的运动应独立。输液器不再移动。现在代码的结果是:在点击滴注刀具之后,条件“if(data.moveWithInfusion === true)”下的代码仍然运行。并且“if(data.moveWithInfusion === false)”下的代码也运行。我找不到原因。有人知道原因吗?谢谢! 所有的https://glitch.com/edit/#!/skill-labAframe:更改att更新
AFRAME.registerComponent('drawerwithinfusioncutlery',{
schema: {
open : {default: '1.8 0 0.1'},
close : {default: '0 0 0.1'},
dur : {default: 300},
moveWithInfusion :{default: true},
},
update: function(){
var data= this.data;
var el=this.el;
var closed=true;
var infusion=document.querySelector("#infusioninpack");
el.addEventListener("click",function(){
if(data.moveWithInfusion===true){
alert("true");
if(closed === true){
open(el, data.close, data.open, data.dur);
open(infusion, '1.24 4.439 1.555', '3.04 4.439 1.555', data.dur);
closed=false;
}else if(closed===false){
open(el, data.open, data.close, data.dur);
open(infusion, '3.04 4.439 1.555', '1.24 4.439 1.555', data.dur);
closed=true;
}
}else if(data.moveWithInfusion===false){
alert("false");
if(closed === true){
open(el, data.close, data.open, data.dur);
closed=false;
}else if(closed===false){
open(el, data.open, data.close, data.dur);
closed=true;
}
}
});
infusion.addEventListener("click",function(){
el.setAttribute('drawerwithinfusioncutlery', {moveWithInfusion: 'false'})
});
}
});
非常感谢你。我的目标是移动抽屉,而不需要在输入刀具上点击一下输入刀具。我用你的建议解决了这个问题。谢谢。 –