Ng-Mousemove-2

 

Ng-mousemove directive call the mouseDown($event) function which calculates X and Y cordinate that is assign to the ng-style of div elements which will show the the circle when we move mouse on the square.

 
 
 
<!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> <style> .circle{ border-radius:50px; } </style> </head> <body ng-app="app"> <div ng-controller="controllerName"> <p>Mouse Move on the square</p> <div style="width:300px;height:300px; background-color:tomato;" ng-mousemove="mouseDown($event)"></div> <div class="circle" ng-style="{ 'backgroundColor':'red', 'margin-top':X+'px', 'margin-left':Y+'px',width:'50px',height:'50px' }" ></div> <div class="circle" ng-style="{ 'backgroundColor':'pink', 'margin-top':X-200+'px', 'margin-left':Y+'px',width:'50px',height:'50px' }" ></div> </div> <pre ng-show="X">Mouse move at:{{X}},{{Y}}</pre> <script> var app = angular.module("app", []); app.controller('controllerName', ['$scope', function ($scope) { $scope.mouseDown = function (event) { $scope.X = event.clientX-100; $scope.Y = event.clientY-100; } }]); </script> </body> </html>
Output