Ng-Mouseenter-2

 

Ng-mouseenter directive call the mouseDown($event) function which calculates X and Y cordinate that is assign to the ng-style of div element which will show the the circle on mouse enter in the div element.

 
 
 
<!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 Enter on the square</p> <div style="width:200px;height:200px; background-color:tomato;" ng-mouseenter="mouseDown($event)"></div> <div class="circle" ng-style="{ 'backgroundColor':'green', 'margin-top':X+'px', 'margin-left':Y+'px',width:'50px',height:'50px' }" > </div> <pre ng-show="X">Mouse enter 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-100; $scope.Y = event.clientY-100; } }]); </script> </body> </html>
Output