【发布时间】:2018-11-15 23:00:11
【问题描述】:
我有一个带有两个箭头和一些对象的框架场景,我尝试在对象之间切换,但我没有正确理解,在这里我得到一些帮助会很好:
AFRAME.registerComponent("fool", {
init: function() {
var boxarray = ["#bluebox, #yellowbox, #greenbox]
boxarray[0] = true;
if(boxarray[0] = true){
document.getElementById('bluebox').setAttribute('visible', 'true');
document.getElementById('bluebox').setAttribute('scale', {x:1,y:1,z:1});
} else {
document.getElementById('bluebox').setAttribute('visible', 'false');
document.getElementById('bluebox').setAttribute('scale', {x:0,y:0,z:0});
}
if(boxarray[1] = true){
document.getElementById('bluebox').setAttribute('visible', 'true');
document.getElementById('bluebox').setAttribute('scale', {x:1,y:1,z:1});
} else {
document.getElementById('bluebox').setAttribute('visible', 'false');
document.getElementById('bluebox').setAttribute('scale', {x:0,y:0,z:0});
}
if(boxarray[2] = true){
document.getElementById('bluebox').setAttribute('visible', 'true');
document.getElementById('bluebox').setAttribute('scale', {x:1,y:1,z:1});
} else {
document.getElementById('bluebox').setAttribute('visible', 'false');
document.getElementById('bluebox').setAttribute('scale', {x:0,y:0,z:0});
}
function toggleright(){
?help?
}
function toggleleft(){
?help?
}
})
我尝试给我所有的对象(盒子)一个事件,所以如果事件也发生变化,改变源只是有用的
【问题讨论】:
-
你需要做
if( boxarray[x] === true)。做一个单一的=是一项任务 -
它需要以不同的方式完成,因为你用 bools 覆盖字符串数组(或用 bools 比较字符串)
标签: javascript arrays function toggle aframe