Ng-Mousemove-3

 

Ng-mousemove directive call the mouseDown($event) function which calculates X and Y cordinate that is assign to the ng-style of div element and size of square increase or decrease when we move mouse on it.

 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> </head> <body ng-app="app"> <div ng-controller="controllerName"> <p>Mouse move on the square</p> <div style="height:10px;width:10px; background-color:red;" ng-style="{'backgroundColor':'lightgreen', width:X+'px',height:Y+'px' }" ng-mousemove="mouseDown($event)"></div> <pre ng-show="X">Mouse move at:{{X}},{{Y}}</pre> </div> <script> var app = angular.module("app", []); app.controller('controllerName', ['$scope', function ($scope) { $scope.mouseDown = function (event) { $scope.X = event.clientX; $scope.Y = event.clientY; }; }]); </script> </body> </html>
Output