Angular Drag Example
How do I make an angular drag example?
Quick sketch of dragging an item with angular. What is a angular drag example? How do you make a angular drag example? This script and codes were developed by Jeff Daze on 18 January 2023, Wednesday.
Angular Drag Example - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Angular Drag Example</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div ng-app="test" ng-controller="testCtrl" id="container"> <div class="shape" ng-draggable='dragOptions'>Drag Me</div>
</div> <script src='http://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Angular Drag Example - Script Codes CSS Codes
html, body{ margin:0; padding:0; width:100%; height:100%;
}
#container { width : 100%; height: 100%; background-color: black;
}
.shape { position: absolute; width : 100px; height: 100px; background-color: white; cursor: move;
}
Angular Drag Example - Script Codes JS Codes
angular.module('test', [])
.directive('ngDraggable', function($document) { return { restrict: 'A', scope: { dragOptions: '=ngDraggable' }, link: function(scope, elem, attr) { //vars... var startX; var startY; var x = 0; var y = 0; var start; var stop; var drag; var container; var width = elem[0].offsetWidth; var height = elem[0].offsetHeight; //drag options... if (scope.dragOptions) { start = scope.dragOptions.start; drag = scope.dragOptions.drag; stop = scope.dragOptions.stop; var id = scope.dragOptions.container; if (id) { container = document.getElementById(id).getBoundingClientRect(); } } //Handle mouse events here... elem.on('mousedown', function(e) { e.preventDefault(); startX = e.clientX - elem[0].offsetLeft; startY = e.clientY - elem[0].offsetTop; $document.on('mousemove', mousemove); $document.on('mouseup', mouseup); if (start) start(e); }); function mousemove(e) { y = e.clientY - startY; x = e.clientX - startX; setPosition(); if(drag){ drag(e); } } function mouseup(e) { $document.unbind('mousemove', mousemove); $document.unbind('mouseup', mouseup); if(stop){ stop(e); } } // Move element, constrain to container if specified... function setPosition() { if (container) { if (x < container.left) { x = container.left; } else if (x > container.right - width) { x = container.right - width; } if (y < container.top) { y = container.top; } else if (y > container.bottom - height) { y = container.bottom - height; } } elem.css({ top: y + 'px', left: x + 'px' }); } } }
})
.controller('testCtrl', function($scope) { $scope.dragOptions = { start: function(e) { console.log("STARTING"); }, drag: function(e) { console.log("DRAGGING"); }, stop: function(e) { console.log("STOPPING"); }, //container: 'container' container: '' }
});
Developer | Jeff Daze |
Username | jeffdaze |
Uploaded | January 18, 2023 |
Rating | 3 |
Size | 2,497 Kb |
Views | 4,048 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
A Pen by Jeff Daze | 2,191 Kb |
Simple handlebars demo | 1,940 Kb |
Tilemap Edge CSS | 2,159 Kb |
JS test and Box Shadow | 1,906 Kb |
Circular Drag and Drop | 2,451 Kb |
A test card for a Munchkin-like game | 2,044 Kb |
An example of postMessage cross origin JS requests | 2,959 Kb |
Pulsing Button | 1,659 Kb |
Angular Drag Example | 2,497 Kb |
Transparent Gradient | 2,735 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Ghost | Mghayour | 11,738 Kb |
Awesome | Samarthpd | 2,901 Kb |
Full page table inside the grid | Twikito | 1,864 Kb |
Blackberry Mock | Zacharyolson | 1,865 Kb |
Z-index demo | Kblh | 1,534 Kb |
Flexbox Grid - equal height | DaveOrDead | 2,855 Kb |
Scarlett Johansson Tribute Page | Diomed | 3,233 Kb |
Svg animation draw | SzymonDziewonski | 5,545 Kb |
WRENCH - STAFF | Lolita-adams | 1,608 Kb |
HTML5 Video Autoplay | Zivcos | 1,352 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!