Ng-Mouseenter-3

 

Ng-mouseenter directive call the mouseDown($event) function which calculates X and Y cordinate that is assign to the ng-style of div element.The position of div element change according to coordinates when we enter the mouse on 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> </head> <body ng-app="app"> <div ng-controller="controllerName"> <p>Mouse Enter on the square</p> <div ng-style="{'backgroundColor':'tomato', 'margin-top':X+'px', 'margin-left':Y+'px',width:'200px',height:'200px' }" ng-mouseenter="mouseDown($event)"></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