Skip to content

Instantly share code, notes, and snippets.

@shamsher31
Created January 8, 2016 12:47
Show Gist options
  • Save shamsher31/dc0c7d03b70583ac26b5 to your computer and use it in GitHub Desktop.
Save shamsher31/dc0c7d03b70583ac26b5 to your computer and use it in GitHub Desktop.
Angular Draggable Container
.directive('draggable', function($document) {
return function(scope, element, attr) {
var startX = 0, startY = 0, x = 0, y = 0;
element.on('mousedown', function(event) {
// Prevent default dragging of selected content
event.preventDefault();
startX = event.screenX - x;
startY = event.screenY - y;
$document.on('mousemove', mousemove);
$document.on('mouseup', mouseup);
});
function mousemove(event) {
y = event.screenY - startY;
x = event.screenX - startX;
$('#video-container').css({
'top': y + 'px',
'left': x + 'px',
'position' : 'absolute'
});
}
function mouseup() {
$document.off('mousemove', mousemove);
$document.off('mouseup', mouseup);
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment