angular拖拽指令-

angular.module('app.routes').directive('dragMvPlayer', ['$document', function($document) {
return{
restrict: 'EA',
template: `testTemplete`,
link: function(scope, element, attr) {
var bodyWidth = document.body.offsetWidth,bodyHeight = document.body.offsetHeight, startX = 0, startY = 0, x = bodyWidth-420, y = bodyHeight - 440;
element= angular.element(document.getElementById("jp_container_1"));
element.css({
position: 'fixed',
cursor: 'move',
});
element.on('mousedown', function(event) {
// Prevent default dragging of selected content
event.preventDefault();
startX = event.pageX - x;
startY = event.pageY - y;
$document.on('mousemove', mousemove);
$document.on('mouseup', mouseup);
});
function mousemove(event) {
y = event.pageY - startY;
x = event.pageX - startX;
element.css({
top: y + 'px',
left: x + 'px'
});
}
function mouseup() {
$document.off('mousemove', mousemove);
$document.off('mouseup', mouseup);
}
}
}
}]);
posted @ 2017-05-31 11:20  json_man  阅读(632)  评论(0编辑  收藏  举报