Dragging in AngularJS

Size
2,859 Kb
Views
34,408

How do I make an dragging in angularjs?

Creating a directive in AngularJS to use jQuery UI's draggable functions.. What is a dragging in angularjs? How do you make a dragging in angularjs? This script and codes were developed by Michael E Conroy on 03 July 2022, Sunday.

Dragging in AngularJS Previews

Dragging in AngularJS - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Dragging in AngularJS</title> <link rel='stylesheet prefetch' href='http://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css'> <link rel="stylesheet" href="css/style.css">
</head>
<body> <html ng-app="dragTest"> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script> <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js" type="text/javascript"></script> <script src="http://code.angularjs.org/1.2.1/angular.min.js" type="text/javascript"></script> </head> <body class="container"> <div class="row"> <div class="col-md-5"> <!-- Draggable Panel --> <div ng-controller="dragCtrlr" class="panel panel-primary" my-draggable="{ addClasses: false,cursor: 'move',handle: '.panel-heading',helper: 'clone',opacity: .75}"> <div class="panel-heading"> <h3 class="panel-title"><span class="glyphicon glyphicon-move"></span> Drag Me</h3> </div> <div class="panel-body"> {{event}} </div> <div class="panel-footer"> <a ng-click="gotoUrl($event,'http://michaeleconroy.blogspot.com/')" class="pull-right"><span class="glyphicon glyphicon-chevron-right"></span> http://michaeleconroy.blogspot.com/</a> <br class="clearfix"> </div> </div> <!-- / .panel --> </div> <!-- / column --> <div class="col-md-4 text-info"> Clicking and holding the panel's title bar will allow you to drag around a clone of the panel. Notice the original panel's body text change when doing so. Letting go of your mouse button will destroy the clone and reset the original's body text. </div> </div> <!-- / row --> </body>
</html> <script src="js/index.js"></script>
</body>
</html>

Dragging in AngularJS - Script Codes CSS Codes

body { padding-top: 25px; }
.panel-heading { cursor: move; }
a[ng-click] { cursor: pointer; }

Dragging in AngularJS - Script Codes JS Codes

angular.module('dragTest',[])
.controller('dragCtrlr',['$scope',function($scope){ $scope.event = 'Nothing currently happening!'; // listen for when the panel is being dragged $scope.$on('dragging',function(evt,params){ $scope.event = 'A clone of me is being dragged around!'; }); // end on(dragging) // listen for when the panel has stopped being dragged $scope.$on('dragging.stopped',function(evt,params){ $scope.event = 'Nothing currently happening!'; }); // end on(dragging.stopped) $scope.gotoUrl = function(evt,url){ evt.preventDefault(); window.location = url; } // end goto
}])
/**
Directive to allow dragging of an object using jQuery UI's draggable functions.
**/
.directive('myDraggable',function(){ return{ restrict: 'A', // directive confined to be an attribute only link: function(scope,el,attrs){ var opts = scope.$eval(attrs.myDraggable); // user $eval because the value of the our attribute is an actual JS Object // $apply is used because jQuery UI events occur outside the context of our directive and its controller and we need them to be "applied" to the scope of our directive var evts = { drag: function(evt){ scope.$apply(function(){ scope.$emit('dragging',{}); }); }, stop: function(evt){ scope.$apply(function(){ scope.$emit('dragging.stopped',{}); }); } }; // end evts (events) var options = $.extend({},opts,evts) // extending the options to feed to the "draggable" function el.draggable(options); // jQuery UI } }
});
Dragging in AngularJS - Script Codes
Dragging in AngularJS - Script Codes
Home Page Home
Developer Michael E Conroy
Username m-e-conroy
Uploaded July 03, 2022
Rating 3
Size 2,859 Kb
Views 34,408
Do you need developer help for Dragging in AngularJS?

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!

Michael E Conroy (m-e-conroy) Script Codes
Create amazing blog posts with AI!

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!