javascript – 在更高的z-index覆盖的元素上悬停事件?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – 在更高的z-index覆盖的元素上悬停事件?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1835字,纯文字阅读大概需要3分钟。
内容图文
我有一个横跨整个屏幕的画布元素(画布 – 鼠标) – 其目的是在特定大小的鼠标周围绘制50%的不透明度圆圈(grabsize).页面上还会有一些div中的图像.我希望这些图像可以点击/可以浏览,但我也希望画布鼠标中的50%不透明度圆圈显示在它们之上.
有没有办法实现这个目标?
HTML:
<canvas id="canvas-mouse" class="fullscreen"></canvas>
<div class="object die"><img src="images/Die_d6.svg"></div>
CSS:
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;
}
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)");
});
提前致谢.
解决方法:
尝试使用pointer-events:none.此规则告诉浏览器忽略元素.鼠标事件不会被它接收,但会“通过”.
#canvas-mouse {
z-index: 10;
pointer-events: none;
}
内容总结
以上是互联网集市为您收集整理的javascript – 在更高的z-index覆盖的元素上悬停事件?全部内容,希望文章能够帮你解决javascript – 在更高的z-index覆盖的元素上悬停事件?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。