如何在AR-JS中将点击事件添加到图像

时间:2020-03-23 13:16:08

标签: javascript augmented-reality ar.js

我正在尝试将点击事件添加到图像标签中,但我无法这样做。有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

尝试添加

<script>
    AFRAME.registerComponent('clickhandler', {
        init: function() {
            this.el.addEventListener('click', () => {
                alert('Clicked!')
            });
    }});
</script>

并将clickhandler属性添加到您的a图片,例如 <a-image clickhandler ... >

来源:https://github.com/AR-js-org/AR.js/blob/master/aframe/examples/location-based/click-places/index.html