单击按钮时 Aframe 循环浏览天空图像源
我正在尝试使用前进和后退按钮循环浏览设置为a-sky
的全景图像。但我在 js 逻辑上遇到了困难。任何帮助表示赞赏。下面的示例在数组中使用了 3 个图像,但实际上会有数百个图像。
function goNext() {
var zerod = 0;
var images = ["https://aframe.io/aframe/examples/boilerplate/panorama/puydesancy.jpg",
"https://aframe.io/aframe/examples/showcase/composite/lake.jpg",
"https://l13.alamy.com/360/PWNBM9/testing-new-cameralens-combination-in-my-garden-in-aarhus-denmark-PWNBM9.jpg"]
function nextimage() {
console.log(zerod)
$("#sky").attr("src", images[zerod])
zerod = (zerod < images.length + 1) ? ++zerod : 0
}
nextimage();
};
function goBack() {
var zerod = 0;
var images = ["https://aframe.io/aframe/examples/boilerplate/panorama/puydesancy.jpg",
"https://aframe.io/aframe/examples/showcase/composite/lake.jpg",
"https://l13.alamy.com/360/PWNBM9/testing-new-cameralens-combination-in-my-garden-in-aarhus-denmark-PWNBM9.jpg"]
function previmage() {
console.log(zerod)
$("#sky").attr("src", images[zerod])
zerod = (zerod < images.length - 1) ? ++zerod : 0
}
previmage();
};
.menu {
position: absolute;
bottom: 15px;
z-index: 2;
right: 15px;
}
.menu a {
display: block;
background: rgba(0, 0, 0, 0.35);
color: white;
padding-left: 5px;
padding-right: 5px;
padding-bottom: 5px;
padding-top: 5px;
text-decoration: none;
font-family: tahoma;
margin: 5px;
text-align: center;
cursor: pointer;
}
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script>
</head>
<body>
<div class="menu">
<!--<br>-->
<a id="forward" onClick="goNext()">Forward</a>
<!--<br>-->
<a id="back" onClick="goBack()">Back</a>
<!--<br>-->
<a id="vr" onclick="document.querySelector('a-scene').enterVR()">VR</a>
</div>
<a-scene image-toggle vr-mode-ui="enabled: false">
<a-assets>
<img id="skybox" src="https://l13.alamy.com/360/PWNBM9/testing-new-cameralens-combination-in-my-garden-in-aarhus-denmark-PWNBM9.jpg">
</a-assets>
<a-sky id="sky" src="#skybox"></a-sky>
<a-camera id="camera" look-controls="pointerLockEnabled: false">
</a-camera>
</a-scene>
</body>
I'm trying to cycle through over panoramic images set as a-sky
, using the forward and back buttons. But I'm struggling with the js logic. Any help is appreciated. The below example uses 3 images in the array, but in practice it'll have hundreds.
function goNext() {
var zerod = 0;
var images = ["https://aframe.io/aframe/examples/boilerplate/panorama/puydesancy.jpg",
"https://aframe.io/aframe/examples/showcase/composite/lake.jpg",
"https://l13.alamy.com/360/PWNBM9/testing-new-cameralens-combination-in-my-garden-in-aarhus-denmark-PWNBM9.jpg"]
function nextimage() {
console.log(zerod)
$("#sky").attr("src", images[zerod])
zerod = (zerod < images.length + 1) ? ++zerod : 0
}
nextimage();
};
function goBack() {
var zerod = 0;
var images = ["https://aframe.io/aframe/examples/boilerplate/panorama/puydesancy.jpg",
"https://aframe.io/aframe/examples/showcase/composite/lake.jpg",
"https://l13.alamy.com/360/PWNBM9/testing-new-cameralens-combination-in-my-garden-in-aarhus-denmark-PWNBM9.jpg"]
function previmage() {
console.log(zerod)
$("#sky").attr("src", images[zerod])
zerod = (zerod < images.length - 1) ? ++zerod : 0
}
previmage();
};
.menu {
position: absolute;
bottom: 15px;
z-index: 2;
right: 15px;
}
.menu a {
display: block;
background: rgba(0, 0, 0, 0.35);
color: white;
padding-left: 5px;
padding-right: 5px;
padding-bottom: 5px;
padding-top: 5px;
text-decoration: none;
font-family: tahoma;
margin: 5px;
text-align: center;
cursor: pointer;
}
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script>
</head>
<body>
<div class="menu">
<!--<br>-->
<a id="forward" onClick="goNext()">Forward</a>
<!--<br>-->
<a id="back" onClick="goBack()">Back</a>
<!--<br>-->
<a id="vr" onclick="document.querySelector('a-scene').enterVR()">VR</a>
</div>
<a-scene image-toggle vr-mode-ui="enabled: false">
<a-assets>
<img id="skybox" src="https://l13.alamy.com/360/PWNBM9/testing-new-cameralens-combination-in-my-garden-in-aarhus-denmark-PWNBM9.jpg">
</a-assets>
<a-sky id="sky" src="#skybox"></a-sky>
<a-camera id="camera" look-controls="pointerLockEnabled: false">
</a-camera>
</a-scene>
</body>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,
goNext()
和goBack()
将zerod
设置为 0;其次,您要在设置源之前更改索引。
想象一下调用
goNext()
和goBack()
:在这种情况下,如果您在
goNext() 之后单击它,则
goBack()
不会执行任何操作最后但并非最不重要的 - 条件:
应该如下所示:
应用以下三点进行检查:
如果将其变成自定义组件:
First of all both
goNext()
andgoBack()
setzerod
to 0;Second of all you want to change the index before setting the source.
Imagine calling
goNext()
andgoBack()
:goBack()
does nothing in this case if you click it aftergoNext()
Last but not least - the conditions:
Should look like this:
Check it out with these three points applied:
Even better if you turn it into a custom component: