1 Star 9 Fork 3

qq123/qcanvas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
template17.html 2.50 KB
一键复制 编辑 原始数据 按行查看 历史
qq123 提交于 2020-08-18 18:24 . 增加右键菜单示例
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="js/jquery.js"></script>
<link href="style/default.min.css" rel="stylesheet">
<link rel="stylesheet" href="style/style.css">
<script src="js/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script src="js/initTemp.js"></script>
<style>
#contextMenu{
position: absolute;
left:0;
top:0;
display: none;
background: #fff;
}
#contextMenu ul li{
padding: 5px;
color: #333;
cursor: pointer;
}
#contextMenu ul li:hover{
background: #ddd;
}
</style>
</head>
<body>
<div class="qcanvas_lay" id="qcanvas_lay">
<canvas id="qcanvas"></canvas>
<div id="contextMenu">
<ul>
<li>菜单一</li>
<li>菜单一</li>
<li>菜单一</li>
</ul>
</div>
</div>
<div class="code_lay">
<pre><code class="js">var qcanvas = new Qcanvas(
{
id:'qcanvas',
width:500,
height:500,
mousedown:function(){
document.getElementById('contextMenu').style.display = 'none';
}
})
var text = qcanvas.qtext.text({
start:[100,100],
color:'blue',
fontSize:'20px',
mousedown:function(){
document.getElementById('contextMenu').style.display = 'none';
},
mouseup:function(e,pos){
if(e.button == '2'){
console.log('text右击');
var doc = document.getElementById('qcanvas_lay')
var left = pos.x - doc.scrollLeft;
var top = pos.y - doc.scrollTop;
var contextMenu = document.getElementById('contextMenu');
contextMenu.style.left = left+'px';
contextMenu.style.top = top+'px';
contextMenu.style.display = "block";
}
},
})
</code>
</pre>
</div>
</body>
<script src='Qcanvas.js'></script>
<script>
var qcanvas = new Qcanvas(
{
id:'qcanvas',
width:500,
height:500,
mousedown:function(){
document.getElementById('contextMenu').style.display = 'none';
}
})
var text = qcanvas.qtext.text({
start:[100,100],
color:'blue',
fontSize:'20px',
mousedown:function(){
document.getElementById('contextMenu').style.display = 'none';
},
mouseup:function(e,pos){
if(e.button == '2'){
console.log('text右击');
var doc = document.getElementById('qcanvas_lay')
var left = pos.x - doc.scrollLeft;
var top = pos.y - doc.scrollTop;
var contextMenu = document.getElementById('contextMenu');
contextMenu.style.left = left+'px';
contextMenu.style.top = top+'px';
contextMenu.style.display = "block";
}
},
})
</script>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lizhicheng99/qcanvas.git
[email protected]:lizhicheng99/qcanvas.git
lizhicheng99
qcanvas
qcanvas
gitee

搜索帮助