Mouse Event in TypeScript: Part 2
Before reading this article, please go through the following articles:
Introduction
A mouse event occurs when a user moves the mouse in the user interface of an application. There are seven types of mouse events; they are:
- Onclick
- Ondblclick
- Onmousedown
- Onmouseup
- Onmouseover
- Onmouseout
- Onmousemove
In this article, I am describing the "Onmouseover" and "Onmouseout" mouse events in TypeScript.
Onmouseover
The onmouseover event occurs when the user moves the mouse pointer into the object. In this example, the smile.gif image is displayed in this event.
Onmouseout
The Onmouseout event occurs when the user moves the mouse pointer out of the object. In this example, the cry.gif image is displayed in this event.
Complete Program
Onmouseover_Onmousedown.ts
- class Image_animation {
- smile() {
- var obj = < HTMLImageElement > document.getElementById("img");
- obj.src = "smile.jpg";
- }
- cry() {
- var obj = < HTMLImageElement > document.getElementById("img");
- obj.src = "cry.jpg";
- }
- }
- window.onload = () => {
- var greeter = new Image_animation();
- var obj = < HTMLImageElement > document.getElementById("img");
- obj.onmouseover = function() {
- greeter.smile();
- }
- obj.onmouseout = function() {
- greeter.cry();
- }
- };
Onmouseover_Onmousedown_Demo.html


Join the conversation! Your thoughts help the community grow.