Here I am explaining each of those mouse events one by one.
- Mouse Over Event: A Mouse Over Event can be fired using the ng-mouseover directive of AngularJS. This event occurs when the mouse pointer hovers on the selected element.
- Mouse Enter Event: A Mouse Enter Event can be fired using the ng-mouseenter directive of AngularJS. This event is the same as the Mouse Over Image (ng-mouseover) event. When the pointer enters the selected element then it will fire.
- Mouse Down Event: AMouse Down Event can be fired using the ng-mousedown directive of AngularJS. This event is fired when the left mouse button is pressed down.
- Mouse Up Event: A Mouse Up Event can be fired using the ng-mouseup directive of AngularJS. This event occurs when the mouse left button is up after pressing down.
- Mouse Leave Event: A Mouse Leave Event can be fired using the ng-mouseleave directive of AngularJS. This event occurs when the mouse pointer leaves the selected element
- Mouse Move Event: A Mouse Move Button can be fired using the ng-mousemove directive of AngularJS. This event occurs when the mouse pointer is moved within the selected element.
How to use it: To use any type of mouse event of AngularJS, you need to specify the directives as an attribute of the HTML Element like:
<ANY MouseEventDirective="{expression}">
...
</ANY>
Use the following procedure to create a sample of using mouse/pointer events.
Step 1:
First of all you need to add an external Angular.js file to your application, for this you can go to the AngularJS official site or download my source code and then fetch it or click on this link and download it: ANGULARJS.
After downloading the external file you need to add this file to the Head section of your application as in the following:
- <!doctype html>
- <html ng-app>
- <head>
- <script src="angular.min.js"></script>
- </head>
Step 2:
Now I will show you the use of various mouse events of AngularJS that are already explained above.
- Use of ng-mouseover: The following code shows how to use ng-mouseover.
- <button ng-mouseover="MouseOverCount = MouseOverCount + 1" ng-init="MouseOverCount=0">
- Increment Value when Mouse over on the Image.
- </button></br>
- Increment on Mouse Over: {{MouseOverCount}}
- </br></br>
Here MouseOverCount is a variable, its initial value is zero, defined by the ng-init directive and its value will be incremented when the mouse will be oven/enter on the button.
- Use of ng-mouseenter: The following code shows how to use ng-mouseenter.
- <button ng-mouseenter="MouseEnterCount = MouseEnterCount + 1" ng-init="MouseEnterCount=0">
- Increment Value when Mouse Enter on The Button
- </button></br>
- Increment on Mouse Enter: {{MouseEnterCount}}
- </br></br>
Here MouseEnterCount is a variable, its initial value is zero, defined by the ng-init directive and its value will increment when the mouse enters the button.
- Use of ng-mousedown: The following code shows how to use ng-mousedown.
- <button ng-mousedown="MouseDownCount = MouseDownCount + 1" ng-init="MouseDownCount=0">
- Increment Value when Mouse Down on the Button
- </button></br>
- Increment on Mouse Down: {{MouseDownCount}}
- </br></br>
Here MouseDownCount is a variable, its initial value is zero, defined by the ng-init directive and its value will increment when the mouse left button is pressed down .
- Use of ng-mouseup: The following code shows how to use ng-mousedown.
- <button ng-mouseup="MouseUpCount = MouseUpCount + 1" ng-init="MouseUpCount=0">
- Increment Value when Mouse Up after Mouse Down
- </button></br>
- Increment on Mouse Up: {{MouseUpCount}}
- </br></br>
Here MouseUpCount is a variable, its initial value is zero, defined by the ng-init directive and its value will increment when the mouse left button is up after pressing down.
- Use of ng-mouseleave: The following code shows how to use ng-mouseleave.
- <button ng-mouseleave="MouseLeaveCount = MouseLeaveCount + 1" ng-init="MouseLeaveCount=0">
- Increment Value when Mouse Leave From the Button
- </button></br>
- Increment on Mouse Leave: {{MouseLeaveCount}}
- </br></br>
Here MouseLeaveCount is a variable, its initial value is zero, defined by the ng-init directive and its value will increment when the mouse leaves from the button.
- Use of ng-mousemove: The following code shows how to use ng-mousemove.
- <button ng-mousemove="MouseMoveCount = MouseMoveCount + 1" ng-init="MouseMoveCount=0">
- Increment Value when Mouse Move on the Button
- </button></br>
- Increment on Mouse Move: {{MouseMoveCount}}
- </br></br>
Here MouseMoveCount is a variable, its initial value is zero, defined by the ng-init directive and its value will increment when the mouse moves on the button.
Complete Code:
- <!doctype html>
- <html ng-app>
- <head>
- <script src="angular.min.js"></script>
- </head>
-
- <body>
-
- <button ng-mouseover="MouseOverCount = MouseOverCount + 1" ng-init="MouseOverCount=0">
- Increment Value when Mouse over on the Image.
- </button></br>
- Increment on Mouse Over: {{MouseOverCount}}
- </br></br>
-
- <button ng-mouseenter="MouseEnterCount = MouseEnterCount + 1" ng-init="MouseEnterCount=0">
- Increment Value when Mouse Enter on The Button
- </button></br>
- Increment on Mouse Enter: {{MouseEnterCount}}
- </br></br>
-
- <button ng-mousedown="MouseDownCount = MouseDownCount + 1" ng-init="MouseDownCount=0">
- Increment Value when Mouse Down on the Button
- </button></br>
- Increment on Mouse Down: {{MouseDownCount}}
- </br></br>
-
- <button ng-mouseup="MouseUpCount = MouseUpCount + 1" ng-init="MouseUpCount=0">
- Increment Value when Mouse Up after Mouse Down
- </button></br>
- Increment on Mouse Up: {{MouseUpCount}}
- </br></br>
-
- <button ng-mouseleave="MouseLeaveCount = MouseLeaveCount + 1" ng-init="MouseLeaveCount=0">
- Increment Value when Mouse Leave From the Button
- </button></br>
- Increment on Mouse Leave: {{MouseLeaveCount}}
- </br></br>
-
-
- <button ng-mousemove="MouseMoveCount = MouseMoveCount + 1" ng-init="MouseMoveCount=0">
- Increment Value when Mouse Move on the Button
- </button></br>
- Increment on Mouse Move: {{MouseMoveCount}}
- </br></br>
-
- </body>
- </html>
OutputHappy Coding :)