How to use the jquery ui draggable method on an ca

2019-02-21 00:44发布

I'm trying to allow the user the ability to move a rectangle around a canvas element using the draggable method.

This was my original thought but it doesn't work.

I have a fiddle set up at http://jsfiddle.net/r2Zbe/

$("button").click(function () {
    var door = bgContext.strokeRect(20, 20, 50, 150);
    door.draggable();
});

3条回答
我想做一个坏孩纸
2楼-- · 2019-02-21 01:04

I would use something like fabricJs, it is much cleaner and easy to use.

查看更多
做自己的国王
3楼-- · 2019-02-21 01:10

jCanvas library says they can let you drag on canvas with jQuery. http://calebevans.me/projects/jcanvas/

They say nothing about jQuery UI though.

Disclaimer: I've never tried it.

查看更多
狗以群分
4楼-- · 2019-02-21 01:27

Not sure about using jQuery UI with canvas, but if you are working with canvas you may want to take a look at EaselJS. It makes everything, including drag and drop, very simple.

EaselJS

查看更多
登录 后发表回答