The cursor changes to I-beam when dragging

My code is below. I also have http://jsfiddle.net/S2JHa/

I don’t understand why the cursor changes to I-ray when I click and drag the mouse over my image.

If I delete "some text", this will not change. This happens in Chrome. FF is fine.

Please, if you can tell how to fix this, I would appreciate it. Thank!

<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");
+3
source share
1 answer

If you do not want interactivity with the canvas, you can cancel the onmousedown event as follows:

canvas.onmousedown = function () {
    return false;
}

Fr IE you need:

canvas.onselectstart = function () { 
    return false;
}

See the updated jsfiddle here: http://jsfiddle.net/S2JHa/11/

+3
source

All Articles