我正在尝试在我的javascript和下面的HTML中的image属性之间创建一个链接,该链接是指向另一个页面的,例如index.html。
这是一个框架,使找到解决方案变得更加困难。
非常感谢您的帮助。
我知道如何用hrefs,基本jquery等创建链接。但是据我所知,这对我的代码不起作用。
<a-entity
id="dialog"
position="0 0 -3"
dialog-popup="
image: img/options1.png;
image2: img/play.png;
></a-entity>
generateImage: function generateImage() {
var _this$data5 = this.data,
src = _this$data5.image,
width = _this$data5.imageWidth,
height = _this$data5.imageHeight,
dialogBoxHeight = _this$data5.dialogBoxHeight;
if (!src.length) {
return null;
}
var image = this.imageEl || document.createElement('a-image');
image.setAttribute('id', "".concat(this.el.getAttribute('id'), "--image"));
image.setAttribute('src', src);
image.setAttribute('width', width);
image.setAttribute('height', height);
image.setAttribute('position', {
x: 0,
y: dialogBoxHeight / 2,
z: 0.5
});
this.hasImage = true;
this.imageEl = image;
return image;
},
我可以以某种方式创建链接,以便用户单击图像时使用我的代码将其带到另一个页面吗?
我正在尝试定位图像:img / options1.png;和image2:img / play.png;
答案 0 :(得分:0)
在最基本的情况下,您需要确保可以“点击” aframe
个元素:
<a-scene cursor="rayOrigin: mouse">
,然后对自定义组件中的click
事件做出反应:
AFRAME.registerComponent("foo", {
schema: {
target: {},
},
init: function() {
this.el.addEventListener('click', (e) => {
window.location = this.data.target;
})
}
})
并像这样使用它:
<a-entity foo="target: www.google.com"></a-entity>
在此glitch上进行检查。单击故障按钮以查看源。