Created
November 27, 2013 11:24
-
-
Save brainwipe/7674201 to your computer and use it in GitHub Desktop.
Snap.svg dragging override using the transform attribute method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="//cdn.jsdelivr.net/snap.svg/0.1.0/snap.svg-min.js"></script> | |
<script> | |
var s = Snap("#svg"); | |
var origTransform = {}; | |
var block = s.rect(100, 100, 100, 100, 20, 20); | |
block.attr({ | |
fill: "rgb(236, 240, 241)", | |
stroke: "#1f2c39", | |
strokeWidth: 3 | |
}); | |
block.drag( | |
function(dx, dy, x, y, e) { | |
// Do your custom work here | |
this.attr({ | |
transform: origTransform + (origTransform ? "T" : "t") + [dx, dy] | |
}); | |
}, | |
function (x,y,e) { | |
origTransform = this.transform().local; | |
} | |
); | |
</script> | |
</head> | |
<body> | |
<svg id="svg" version="1.1" xmlns="http://www.w3.org/2000/svg"></svg> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Snap.svg http://snapsvg.io/
More detail on my blog: http://robsneuron.blogspot.co.uk/