Home >Web Front-end >JS Tutorial >Angularjs creates a pop-up box to achieve dragging effect_AngularJS
The example in this article introduces the relevant code for creating a pop-up box in angularjs to achieve the drag effect. In the project, the pop-up box used in angular-ui-bootstrap needs to be made draggable and shared with everyone for your reference. The specific content As follows
Operation rendering:
Since it is not implemented in the source file, you need to implement the instruction yourself. The following is the instruction. It can be implemented by personal testing.
.directive('draggable', ['$document', function($document) { return function(scope, element, attr) { var startX = 0, startY = 0, x = 0, y = 0; element= angular.element(document.getElementsByClassName("modal-dialog")); element.css({ position: 'relative', 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); } }; }]);
The above is the entire content of this article, I hope it will be helpful to everyone’s study.