我的代码如下。我也在http://jsfiddle.net/S2JHa/
当我点击并将鼠标拖到我的照片上时,我不明白为什么光标会变为工字梁。
如果我删除"某些文字"然后它不会改变。这种情况发生在Chrome中。 FF很好。
如果你能说出如何解决这个问题,我将不胜感激。 谢谢!
<div id="window">
<div>some text</div>
<div id="sketch" class="box">
<div class="contents">
<canvas id="image-layer"></canvas>
</div>
</div>
</div>
CSS:
#window #sketch
{
padding: 1cm 0;
}
#window #sketch canvas
{
left: 0;
position: absolute;
top: 0;
}
#window #sketch .contents
{
cursor: crosshair;
position: relative;
}
div.box
{
background-color: #fff;
border: 1px solid black;
border-radius: 0.3cm;
cursor: move;
left: 0;
position: fixed;
top: 0;
}
JavaScript的:
function image_onload(e) {
var image = e.target;
$("div.box").draggable({
cancel: "div.box div.contents",
containment: "document"
});
var x = $("#window #sketch");
// size to fit image
x.css("width", image.width);
x.css("height", image.height);
// center sketch inside parent window
x.css("left", ($(window).width() - x.width()) / 2);
var canvas = document.getElementById("image-layer");
canvas.height = image.height;
canvas.width = image.width;
var context = canvas.getContext("2d");
context.drawImage(image, 0, 0);
}
function open(url) {
var image = new Image();
image.src = url;
image.onload = image_onload;
}
open("http://upload.wikimedia.org/wikipedia/commons/6/63/Wikipedia-logo.png");
答案 0 :(得分:3)
如果您不想与画布进行交互,可以取消onmousedown事件,如下所示:
canvas.onmousedown = function () {
return false;
}
Fr IE,你需要:
canvas.onselectstart = function () {
return false;
}
请在此处查看更新的jsfiddle:http://jsfiddle.net/S2JHa/11/