Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cursor changes back to I-beam when dragging

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

I do not understand why cursor changes to I-beam when I click and drag the mouse over my picture.

If I remove "some text" then it does not change. This happens in Chrome. FF is fine.

Please if you can tell how to fix that I would appreciate it. Thanks!

<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");
like image 950
akonsu Avatar asked Feb 18 '26 22:02

akonsu


1 Answers

If you don't want interactivity with the canvas you can cancel the onmousedown event like so:

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

Fr IE you will need:

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

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

like image 195
Graham Conzett Avatar answered Feb 21 '26 11:02

Graham Conzett



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!