Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将事件悬停在z索引较高的元素上?_Javascript_Jquery_Html_Css_Canvas - Fatal编程技术网

Javascript 将事件悬停在z索引较高的元素上?

Javascript 将事件悬停在z索引较高的元素上?,javascript,jquery,html,css,canvas,Javascript,Jquery,Html,Css,Canvas,我有一个画布元素(canvas mouse),它横跨整个屏幕-它的目的是在鼠标周围画一个50%不透明度的圆圈,大小为一定的(grabsize)。页面上还有许多div中的图像。我希望这些图像可以点击/悬停,但我也希望画布鼠标中的50%不透明度圆圈出现在它们上面 有没有办法做到这一点 HTML: JavaScript: CanvasRenderingContext2D.prototype.drawCircle = function(xpos, ypos, radius, linewidth, lin

我有一个画布元素(
canvas mouse
),它横跨整个屏幕-它的目的是在鼠标周围画一个50%不透明度的圆圈,大小为一定的(
grabsize
)。页面上还有许多div中的图像。我希望这些图像可以点击/悬停,但我也希望
画布鼠标中的50%不透明度圆圈出现在它们上面

有没有办法做到这一点

HTML:

JavaScript:

CanvasRenderingContext2D.prototype.drawCircle = function(xpos, ypos, radius, linewidth, linecolor, fill) {
    if(typeof(linewidth)==="undefined") {
        linewidth = 1;
    }
    if(typeof(linecolor)==="undefined") {
        linecolor = "#000000";
    }

    this.beginPath();
    this.arc(xpos, ypos, radius, 0, 2*Math.PI, false);
    this.lineWidth = linewidth;
    if(typeof(fill)!=="undefined") {
        this.fillStyle = fill
        this.fill();
    }
    this.strokeStyle = linecolor;
    this.stroke();
}
CanvasRenderingContext2D.prototype.maximize = function() {
    this.canvas.width = window.innerWidth;
    this.canvas.height = window.innerHeight;
}
mousectx = $("#canvas-mouse")[0].getContext("2d");
mousectx.maximize();

//Dice handlers
$(".object.die").hover(function() {
    //Hover event goes here
})
$(".object.die").mousedown(function() {
    //Click event goes here
})

//Mouse movement handler
$(document).mousemove(function(e){
    //Get the mouse positions and put them in {mouse}
    mouse.x = e.pageX;z
    mouse.y = e.pageY;

    //Redraw the grab circle
    mousectx.clearCanvas();
    mousectx.drawCircle(mouse.x,mouse.y,grabsize,1,"#000000","rgba(0,0,255,0.5)");
});

提前感谢。

尝试使用
指针事件:无
。此规则告诉浏览器忽略某个元素。它不会接收鼠标事件,但会“通过”


这可能会解决这个问题。画布鼠标不应该有一个相对位置来运行z索引吗?
html, body {
    width:  100%;
    height: 100%;
    margin: 2px;
    overflow: hidden;
    color: #FFFFFF;
    background-color: #2C744C;
}

canvas.fullscreen {
    position: absolute;
    left: 0px;
    top: 0px;
    z-index: -1;
}

.object {
    position: absolute;
}

#canvas-mouse {
    z-index: 10;
}
CanvasRenderingContext2D.prototype.drawCircle = function(xpos, ypos, radius, linewidth, linecolor, fill) {
    if(typeof(linewidth)==="undefined") {
        linewidth = 1;
    }
    if(typeof(linecolor)==="undefined") {
        linecolor = "#000000";
    }

    this.beginPath();
    this.arc(xpos, ypos, radius, 0, 2*Math.PI, false);
    this.lineWidth = linewidth;
    if(typeof(fill)!=="undefined") {
        this.fillStyle = fill
        this.fill();
    }
    this.strokeStyle = linecolor;
    this.stroke();
}
CanvasRenderingContext2D.prototype.maximize = function() {
    this.canvas.width = window.innerWidth;
    this.canvas.height = window.innerHeight;
}
mousectx = $("#canvas-mouse")[0].getContext("2d");
mousectx.maximize();

//Dice handlers
$(".object.die").hover(function() {
    //Hover event goes here
})
$(".object.die").mousedown(function() {
    //Click event goes here
})

//Mouse movement handler
$(document).mousemove(function(e){
    //Get the mouse positions and put them in {mouse}
    mouse.x = e.pageX;z
    mouse.y = e.pageY;

    //Redraw the grab circle
    mousectx.clearCanvas();
    mousectx.drawCircle(mouse.x,mouse.y,grabsize,1,"#000000","rgba(0,0,255,0.5)");
});
#canvas-mouse {
    z-index: 10;
    pointer-events: none;
}