-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmouseEvent.html
64 lines (64 loc) · 2.05 KB
/
mouseEvent.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Mouse Event Object</title>
<style>
strong {
font-size: 20px;
}
.box {
display: inline-block;
width: 100px;
height: 100px;
background-color: black;
}
</style>
</head>
<body>
<h1>The Mouse Event Object</h1>
<p>Events that occurs when the mouse interacts with HTML elements</p>
<div class="wrapper">
<p id="pTag" onmousedown="mouseDown()" onmouseup="mouseUp()">
<strong> onmousedown: </strong>The event occurs when the user presses a
mouse button over an element.
<br />
<strong> onmouseup:</strong> The event occurs when a user releases a
mouse button over an element.
</p>
</div>
<hr />
<div>
<p id="pTag2">
<strong>onmouseenter:</strong> The event occurs when the pointer is
moved onto an element.
<br />
<strong>onmouseleave:</strong> The event occurs when the pointer is
moved out of an element.
</p>
<div class="box" id="box1"></div>
<div class="box" id="box2"></div>
</div>
<script>
const mouseMovement = document.getElementById("pTag");
const mouseEnter = document.getElementById("box1");
const mouseLeave = document.getElementById("box2");
const mouseUp = () => {
mouseMovement.style.color = "#f14e0d";
};
const mouseDown = () => {
mouseMovement.style.color = "black";
};
mouseEnter.addEventListener("mouseenter", () => {
mouseEnter.style.backgroundColor = "green";
mouseEnter.innerHTML = "Mouse enter";
});
mouseLeave.addEventListener("mouseleave", () => {
mouseLeave.style.backgroundColor = "green";
mouseLeave.innerHTML = "Mouse Leave";
});
</script>
</body>
</html>