编程语言
首页 > 编程语言> > javascript – aFrame.io创建超链接和下载链接

javascript – aFrame.io创建超链接和下载链接

作者:互联网

您好我刚开始使用A-Frame.io并且发现该网站非常有用.但是,如果我查看对象,则没有关于如何使链接工作的文档.

https://aframe.io/examples/showcase/cursor/

在上面的例子中,如果使用鼠标中键将光标悬停在立方体上,它会改变形状.

有没有办法在触发该多维数据集时使Web链接正常工作.

<!DOCTYPE html>
<html>
   <head>
<meta charset="utf-8">
<title>Cursor</title>
<meta name="description" content="Cursor — A-Frame">
<script src="../../dist/aframe.js"></script>
 </head>
 <body>
<a-scene>
  <a-entity position="0 1.8 4">
    <a-camera id="camera">
      <a-cursor color="#4CC3D9"></a-cursor>
    </a-camera>
  </a-entity>

  <a-box id="orange-cube" position="0 3.5 -2" rotation="30 30 0" width="2" depth="2" height="2" color="#F16745" roughness="0.8">
    <a-event name="mouseenter" scale="3 1 1" color="#FFC65D"></a-event>
    <a-event name="mouseenter" target="#shadow" scale="3 2 2"></a-event>
    <a-event name="mouseleave" scale="1 1 1" color="#F16745"></a-event>
    <a-event name="mouseleave" target="#shadow" scale="2 2 2"></a-event>
  </a-box>

  <a-image id="shadow" position="0 0 -2" src="../_images/radial-shadow-2.png" opacity="0.5" rotation="-90 0 0" scale="2 2 2"></a-image>
  <a-sky color="#ECECEC"></a-sky>
</a-scene>
 </body>
</html>

解决方法:

您可以添加事件侦听器,也可以编写链接组件.

el.addEventListener('click', function () {
  window.location.href = 'https://google.com';
});

零件:

AFRAME.registerComponent('link', {
  schema: {default: ''},

  init: function () {
    var url = this.data;
    this.el.addEventListener('click', function () {
      window.location.href = url;
    });
  }
});

“`

标签:javascript,aframe,webvr
来源: https://codeday.me/bug/20190519/1135359.html