I’m trying to get a draggable image in Dart. Though setting the draggable bool of my image doesn’t work.
image = new ImageElement();
image.src = ImageSourceByName(name);
image.on.load.add((event) {Context.drawImage(image, 10, 10, CARD_SMALL_WIDTH, CARD_SMALL_HEIGHT);});
image.draggable = true;
(Note: Context is the 2D context I get from my Canvas.)
The drawing works perfectly, I can see my card, though I can’t drag it around. I’m pretty new to Dart, so it might be something obvious, though I can’t find any tutorial explaining it.
You’re using an ImageElement as the source to paint something on your CanvasElement.
Once the pixels are on the canvas(through drawImage()), your image data is not an HTMLElement but, well, pixels 🙂
The
draggableattr, however, is an attribute of an HTMLElement.If you add the image to your document, you’ll notice that you can study the behaviour of
draggable, like this:document.body.nodes.add(image);If you ‘only’ want to have draggable images, you can take it from there and maybe look at http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html
Otherwise, if you want stuff on a canvas to be draggable, thats a different(more complicated?) story.