Javascript 如何在a-frame中与html代码交互

Javascript 如何在a-frame中与html代码交互,javascript,html,three.js,aframe,webvr,Javascript,Html,Three.js,Aframe,Webvr,我正在使用a-frame组件将2d html插入到平面上的场景中。出于某种原因,我的html没有一个是可交互的。我目前正在尝试创建一个白板,并将其插入到2d平面上的场景中,但我无法与代码交互,也无法将鼠标放在白板上绘制。什么都没有发生。有人知道如何使我的代码可交互,这样当我点击白板时,我就可以与它交互,并在我的鼠标按下时在它上绘图吗?代码在3d中运行良好,但当我将其加载到场景中时,我无法与代码交互。这是我目前的代码 <!DOCTYPE html-> <html> <

我正在使用a-frame组件将2d html插入到平面上的场景中。出于某种原因,我的html没有一个是可交互的。我目前正在尝试创建一个白板,并将其插入到2d平面上的场景中,但我无法与代码交互,也无法将鼠标放在白板上绘制。什么都没有发生。有人知道如何使我的代码可交互,这样当我点击白板时,我就可以与它交互,并在我的鼠标按下时在它上绘图吗?代码在3d中运行良好,但当我将其加载到场景中时,我无法与代码交互。这是我目前的代码

 <!DOCTYPE html->
<html>
<head>
  <title>My A-Frame Scene</title>
  <script src="https://aframe.io/releases/0.9.2/aframe.min.js"></script>
  <script src="https://supereggbert.github.io/aframe-htmlembed-component/dist/build.js"></script>
</head>

<body>
  <a-scene>
    <a-entity  geometry="primitive: plane; height: 10; width: 10; color: white;" target  position="0 1.6 -1" htmlembed>

<script type="text/JavaScript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js?ver=1.4.2"></script>

    <canvas id="myCanvas">
        Sorry, your browser does not support HTML5 canvas technology.
    </canvas>
<style>
      * {
    margin: 0;
    padding: 0;
}

body, html {
    height: 100%;
}

#myCanvas {
    cursor: crosshair;
    position: fixed;
}</style>
    <script>
      window.onload = function() {
    var myCanvas = document.getElementById("myCanvas");
    var ctx = myCanvas.getContext("2d");
    
    // Fill Window Width and Height
    myCanvas.width = window.innerWidth;
    myCanvas.height = window.innerHeight;
    
    // Set Background Color
    ctx.fillStyle="#fff";
    ctx.fillRect(0,0,myCanvas.width,myCanvas.height);
    
    // Mouse Event Handlers
    if(myCanvas){
        var isDown = false;
        var canvasX, canvasY;
        ctx.lineWidth = 5;
        
        $(myCanvas)
        .mousedown(function(e){
            isDown = true;
            ctx.beginPath();
            canvasX = e.pageX - myCanvas.offsetLeft;
            canvasY = e.pageY - myCanvas.offsetTop;
            ctx.moveTo(canvasX, canvasY);
        })
        .mousemove(function(e){
            if(isDown !== false) {
                canvasX = e.pageX - myCanvas.offsetLeft;
                canvasY = e.pageY - myCanvas.offsetTop;
                ctx.lineTo(canvasX, canvasY);
                ctx.strokeStyle = "#000";
                ctx.stroke();
            }
        })
        .mouseup(function(e){
            isDown = false;
            ctx.closePath();
        });
    }
    
    // Touch Events Handlers
    draw = {
        started: false,
        start: function(evt) {

            ctx.beginPath();
            ctx.moveTo(
                evt.touches[0].pageX,
                evt.touches[0].pageY
            );

            this.started = true;

        },
        move: function(evt) {

            if (this.started) {
                ctx.lineTo(
                    evt.touches[0].pageX,
                    evt.touches[0].pageY
                );

                ctx.strokeStyle = "#000";
                ctx.lineWidth = 5;
                ctx.stroke();
            }

        },
        end: function(evt) {
            this.started = false;
        }
    };
    
    // Touch Events
    myCanvas.addEventListener('touchstart', draw.start, false);
    myCanvas.addEventListener('touchend', draw.end, false);
    myCanvas.addEventListener('touchmove', draw.move, false);
    
    // Disable Page Move
    document.body.addEventListener('touchmove',function(evt){
        evt.preventDefault();
    },false);
};</script>
    </a-entity>
  </a-scene>
</body>
    

</html>

我的A帧场景
抱歉,您的浏览器不支持HTML5画布技术。
* {
保证金:0;
填充:0;
}
正文,html{
身高:100%;
}
#我的画布{
光标:十字线;
位置:固定;
}
window.onload=函数(){
var myCanvas=document.getElementById(“myCanvas”);
var ctx=myCanvas.getContext(“2d”);
//填充窗的宽度和高度
myCanvas.width=window.innerWidth;
myCanvas.height=window.innerHeight;
//设置背景色
ctx.fillStyle=“#fff”;
fillRect(0,0,myCanvas.width,myCanvas.height);
//鼠标事件处理程序
如果(我的画布){
var isDown=假;
var canvasX,canvasY;
ctx.lineWidth=5;
$(myCanvas)
.mousedown(函数(e){
isDown=真;
ctx.beginPath();
canvasX=e.pageX-myCanvas.offsetLeft;
canvasY=e.pageY-myCanvas.offsetTop;
ctx.moveTo(canvax,canvasY);
})
.mousemove(函数(e){
如果(isDown!==false){
canvasX=e.pageX-myCanvas.offsetLeft;
canvasY=e.pageY-myCanvas.offsetTop;
ctx.lineTo(画布,画布);
ctx.strokeStyle=“#000”;
ctx.stroke();
}
})
.mouseup(函数(e){
isDown=假;
ctx.closePath();
});
}
//触摸事件处理程序
抽签={
开始:错,
启动:功能(evt){
ctx.beginPath();
移动到(
evt.touch[0]。第x页,
evt.touchs[0]。页面
);
this.started=true;
},
移动:功能(evt){
如果(此.started){
ctx.lineTo(
evt.touch[0]。第x页,
evt.touchs[0]。页面
);
ctx.strokeStyle=“#000”;
ctx.lineWidth=5;
ctx.stroke();
}
},
结束:功能(evt){
this.start=false;
}
};
//触摸事件
myCanvas.addEventListener('touchstart',draw.start,false);
myCanvas.addEventListener('touchend',draw.end,false);
myCanvas.addEventListener('touchmove',draw.move,false);
//禁用页面移动
document.body.addEventListener('touchmove',function(evt){
evt.preventDefault();
},假);
};
有人知道我可以在vr中像在普通2d屏幕上一样与白板交互吗