Created
January 8, 2016 12:47
-
-
Save shamsher31/dc0c7d03b70583ac26b5 to your computer and use it in GitHub Desktop.
Angular Draggable Container
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
.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