Skip to content

Instantly share code, notes, and snippets.

@fpauser
Created April 14, 2014 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fpauser/10682394 to your computer and use it in GitHub Desktop.
Save fpauser/10682394 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
<style>
#app {
width:300px;
height:300px;
background:#eaeded;
padding:50px;
}
#fake-svg {
position:absolute;
width:200px;
padding:10px;
background:#aaa;
}
.drag-helper {
position:absolute;
background-color:#00aaff!important;
opacity:0.6;
}
</style>
<script>
function doIt() {
$("#fake-svg").draggable({
axis: "x",
helper: function() {
var $this = $(this),
$handle = $("<div class='drag-helper'>");
$handle.css({
width: $this.outerWidth(),
height: $this.outerHeight(),
top: $this.position().top
});
return $handle;
},
drag: function(e, ui) {
var $elm = $(e.target),
offset = $elm.offset(),
diff = ui.offset.left - offset.left;
$elm.css({top: ui.originalPosition.top + diff});
}
});
}
$(doIt);
</script>
</head>
<body>
<div id="app">
<div id="fake-svg">
FAKE SVG
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment