JSFiddle - React, Tailwind, and code Playground
HTML
<div id="canvas"></div>
JavaScript
window.onload = function() {
var nowX, nowY, w = 300, h=300, r=30, R = Raphael("canvas", w, h),
c = R.circle(100, 100, r).attr({
fill: "hsb(.8, 1, 1)",
stroke: "none",
opacity: .5,
cursor: "move"
});
var start = function () {
// storing original coordinates
this.ox = this.attr("cx");
this.oy = this.attr("cy");
this.attr({opacity: 1});
},
move = function (dx, dy) {
// move will be called with dx and dy
// restrict movement of circle to within boundaries
nowX = Math.max(0 + r, this.ox + dx);
nowY = Math.max(0 + r, this.oy + dy);
nowX = Math.min(w - r, nowX);
nowY = Math.min(h - r, nowY);
this.attr({cx: nowX, cy: nowY});
},
up = function () {
// restoring state
this.attr({opacity: .5});
};
c.drag(move, start, up);
};