更改 按下按钮时带有javascript ID的材质

问题描述 投票:0回答:1

所以我有以下代码:

 function pictureChange()
  {
   document.getElementById("theImage").src="img02.png";
  }
<a-mixin id="voxel"
         geometry="primitive: box; height: 0.6; width: 0.6; depth: 0.6"
         material="id: theImage; src: Box.jpg; color: #696969; roughness: 1; metalness: 0"     
         snap="offset: 0.4 0.4 0.4; snap: 0.6 0.6 0.6"
      ></a-mixin>

我想使用ID“theImage”将图像URL更改为其他内容,但Aframe中的CSS3不能正常运行,因此无法使其正常运行。如果有人有任何想法可以帮助我,我将非常感激。谢谢。

PS:澄清一下,我想通过按下按钮来改变网址。

javascript html aframe
1个回答
0
投票

id指的是实体或资产,而不是材料。尝试在mixin上设置图像:

  var mixinEl = document.getElementById('voxel');
  mixinEl.setAttribute('material','src: #super');

示例:https://glitch.com/edit/#!/swamp-sparrow?path=index.html:1:0

© www.soinside.com 2019 - 2024. All rights reserved.