【问题标题】:Can anyone help me update this javascript to create a link to another page谁能帮我更新这个 javascript 以创建指向另一个页面的链接
【发布时间】:2019-04-15 05:44:41
【问题描述】:

我正在尝试在我的 javascript 和下面显示的 HTML 中的 image 属性之间创建一个链接,该链接指向另一个页面,例如index.html。

这是在框架中,因此更难找到解决方案。

非常感谢任何帮助。

我知道如何使用 href、基本 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;具体来说。

【问题讨论】:

  • 所以&lt;a href="some other page"&gt;&lt;img src="some image url"/&gt;&lt;/a&gt; ?
  • 不,更准确地说我想制作 img/options1.png;和image2:img/play.png;可点击的链接,有什么办法可以做到这一点。

标签: javascript hyperlink var aframe


【解决方案1】:

在最基本的情况下,您需要确保可以“点击”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。单击故障按钮以查看源。


类似的 SO 问题 herehere

【讨论】:

  • 您好,感谢您的帮助。这允许我将整个 a-entity 设置为可点击的链接,但我应该进一步澄清一下,我只想要图像:img/options1.png;和image2:img/play.png;要成为可点击的链接,有没有办法可以做到这一点。
  • @Zecele 查看this glitch。是不是在你的脑海里?
  • 嗨,非常感谢,但这似乎不是我所追求的。我将在下面链接我目前拥有的内容:github.com/AndrewMC1994/Image-Link-Test 基本上我有一个弹出框,其中有两个图像在标题卡和我想要的播放按钮,一旦用户单击播放按钮被带到另一个页面。我想定位 image2: img/play.png;
猜你喜欢
  • 2015-06-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多