Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript A帧集属性不适用于平面';s的高度和宽度_Javascript_Aframe_Webvr - Fatal编程技术网

Javascript A帧集属性不适用于平面';s的高度和宽度

Javascript A帧集属性不适用于平面';s的高度和宽度,javascript,aframe,webvr,Javascript,Aframe,Webvr,我正在尝试建立一个虚拟现实网站。我需要代码做的一件事是,当我单击雕像时,我的平面和文本可以切换可见性。在下面的代码中,当我单击ParkStation时,park和parkPlane都应该消失或可见。文本工作正常,但平面不变。理论上,高度和宽度会发生变化(变为0并返回),但不会调整大小。我做错了什么 演示: 使用框架 <head> <script src="https://aframe.io/releases/0.8.2/aframe.min.js"> </s

我正在尝试建立一个虚拟现实网站。我需要代码做的一件事是,当我单击雕像时,我的平面和文本可以切换可见性。在下面的代码中,当我单击ParkStation时,park和parkPlane都应该消失或可见。文本工作正常,但平面不变。理论上,高度和宽度会发生变化(变为0并返回),但不会调整大小。我做错了什么

演示:

使用框架

<head>
    <script src="https://aframe.io/releases/0.8.2/aframe.min.js"> </script>
</head>

<body>
    <script>

        var proj={
            park:'Pakinsons',
            anant: "Anant"
        }

        function visible(idBase) {
            // get the clock
            console.log("Clicked: "+idBase)
            var plane=document.getElementById(idBase+'Plane')
            var text=document.getElementById(idBase)
            console.log(plane.getAttribute('visible'))
            if(text.getAttribute('value')!=' '){
                text.setAttribute('value'," ")
                plane.setAttribute('height', 0)
                plane.setAttribute('width', 0)
                plane.setAttribute('visible',false)
                // plane.height="0000"
                // plane.width="0000"


            }else{
                text.setAttribute('value',proj[idBase])
                plane.setAttribute('height', ".00010")
                plane.setAttribute('width', ".00010")
                plane.setAttribute('visible',true)

                // plane.height=".00010"
                // plane.width=".00010"

            }
        }

    </script>

    <a-scene>   

            <a-camera position="2 3 0">
            <a-cursor color="#FF0000">
        </a-camera>

>
        <a-gltf-model id="sheep" position="0 0 -3" rotation="0 100 0" 
            src="https://cdn.glitch.com/0fc2d138-1979-4b80-8bae-51eb67b7ccb9%2Fsheep.glb?1544159918188">
        </a-gltf-model>


        <a-gltf-model id="parkStatue" position="-4 2 -11" rotation="0 15 0" scale=".04 .04 .04" onclick="visible('park')"
                src="https://cdn.glitch.com/7e18fbf8-9686-4cf7-91f9-4a6bbdb54f5e%2Fstatue.glb?1544169724449">
        </a-gltf-model>

        <a-plane id='parkPlane' position="-1 1.69 -2.5" rotation="0 10 0"  height=".00010" 
        color="#faaf52" width=".00010"></a-plane>    
<a-text id='park' value="Parkinsons" position="-2.15 2 -2.29" rotation="0 10 0" width="4" color="black" ></a-text>


        <a-sky src="https://cdn.glitch.com/7e18fbf8-9686-4cf7-91f9-4a6bbdb54f5e%2Fsky.jpg?1544174075054"></a-sky>

        <a-plane id="floor" position="0 0 0" rotation="-90 0 0" width="30" height="30" repeat="5 4"
            src="https://cdn.glitch.com/c388f728-37b7-4af9-af03-1ee7430663e7%2F4727356277_66fb5f938f_o.jpg?1544178281422">
        </a-plane>

        <a-plane position="-1 1.69 -2.5" rotation="0 10 0" scale="2.75 1 1" color="#faaf52"></a-plane>

        <a-plane position="2 1 -2.5" rotation="0 -10 0" scale="2 .8 1" color="#faaf52"></a-plane>
        <a-text value="On desktop, click + drag to look around, and use the awsd keys to move around."
            position="1.12 1.23 -2.6" rotation="0 -10 0" width="1.9" color="black"></a-text>
        <a-text value="In Go/Daydream/GearVR or mobile, look around. On Rift, Vive, or WinMR, you can also walk around!"
            position="1.09 1 -2.6" rotation="0 -10 0" width="1.9" color="black"></a-text>

        <a-dodecahedron position="-8 2 -1" color="yellow"></a-dodecahedron>

        <a-sphere position="10 2 0" color="orange" scale=".6 .6 .6"></a-sphere>
        <a-sphere position="10 1.5 -1" color="brown" scale=".4 .4 .4"></a-sphere>
        <a-sphere position="10 1.5 1" color="brown" scale=".4 .4 .4"></a-sphere>
        <a-sphere position="10 2.7 .8" color="brown" scale=".4 .4 .4"></a-sphere>


        <a-plane position="0 1.5 -15" color="#643200" scale="30 3 30"></a-plane>
        <a-plane position="15 1.5 0" rotation="0 -90 0" color="#643200" scale="30 3 30"></a-plane>
        <a-plane position="0 1.5 15" rotation="0 180 0" color="#643200" scale="30 3 30"></a-plane>
        <a-plane position="-15 1.5 0" rotation="0 90 0" color="#643200" scale="30 3 30"></a-plane>


        <a-box position="4 1 -8" scale="2 2 2" color="black"></a-box>
        <a-torus-knot position="4 4 -8" color="#408080"></a-torus-knot>

        <a-box position="-10 1 -10" scale=".5 2 .5" color="#552b00"></a-box>
        <a-cone position="-10 3.2 -10" color="green" scale="1 3 1"></a-cone>

        <a-box position="-9 1 -12" scale=".5 2 .5" color="#552b00"></a-box>
        <a-cone position="-9 3.2 -12" scale="1 3 1" color="green"></a-cone>

        <!-- tree -->
        <a-box position="10 1 10" scale=".5 2 .5" color="#552b00"></a-box>
        <a-cone position="10 3.2 10" color="green" scale="1 3 1"></a-cone>

        <!-- tree -->
        <a-box position="9 1 12" scale=".5 2 .5" color="#552b00"></a-box>
        <a-cone position="9 3.2 12" scale="1 3 1" color="green"></a-cone>

        <a-box position="-8 3 10" rotation="0 -45 0" scale="6 2 2" color="#80ffff"></a-box>
        <a-box position="-8 1 10" rotation="0 -45 0" scale="1 2 1" color="#592d00"></a-box>

        <a-box position="0 1 10" scale="2 2 2" color="black"></a-box>
        <a-tetrahedron position="0 3.5 10" rotation="-12 -180 65" color="#FF926B" radius="5" scale=".5 .5 .5">
        </a-tetrahedron>


    </a-scene>

</body>

</html>


var项目={
帕克:“巴基斯坦人”,
阿南特:“阿南特”
}
函数可见(idBase){
//拿钟
log(“单击:”+idBase)
var plane=document.getElementById(idBase+'plane')
var text=document.getElementById(idBase)
console.log(plane.getAttribute('visible'))
if(text.getAttribute('value')!=“”){
text.setAttribute('value',“”)
plane.setAttribute('height',0)
plane.setAttribute('width',0)
plane.setAttribute('visible',false)
//平面高度=“0000”
//平面宽度=“0000”
}否则{
text.setAttribute('value',proj[idBase])
plane.setAttribute('height',“.00010”)
plane.setAttribute('width',“.00010”)
plane.setAttribute('visible',true)
//平面高度=“.00010”
//平面宽度=“.00010”
}
}
>

您的代码按预期工作,但a-Frame上存在错误。将“宽度”和“高度”设置为0将设置几何图形的默认值,而不是0。我任何其他值都应按预期工作。在您的情况下,不需要将高度和宽度设置为0,因为您正在隐藏实体

仅供参考,您使用的是旧的A-Frame版本。使用1.0.4或更新版本


检查您的HTML是否有效。e、 g:Hey没有结束标记。隐藏也不起作用。添加了一个带有demoBetter to use glitch的网站,这样人们就可以修改代码并提供替代方案。也有助于将代码简化为与问题相关的代码。