-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmouse-events-lecture.html
More file actions
181 lines (131 loc) · 4.61 KB
/
mouse-events-lecture.html
File metadata and controls
181 lines (131 loc) · 4.61 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Mouse Events Lecture</title>
<!-- Bootstrap Core CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<style>
.box {
height: 200px;
width: 200px;
background-color: red;
}
</style>
</head>
<body>
<main id="container" class="container mt-5">
<h1>Mouse Events Lecture</h1>
<h3 class="blue-text">Sub Header</h3>
<p class="blue-text">
This is paragraph 1.
</p>
<p class="blue-text">
This is paragraph 2.
</p>
<hr>
<ul>
<li>Item 1</li>
<li id="special-item">Item 2</li>
<li>Item 3</li>
</ul>
<div class="box" id="box"></div>
</main>
<script src="http://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>
<script>
// $(document).ready(function(){
"use strict";
// Event Handler / Listener Function Review from JavaScript
// with anon function
// var mainContainer = document.getElementById('container');
//
// mainContainer.addEventListener("click", function(e) {
// console.log(e);
// });
// with defined handler
// var mainContainer = document.getElementById('container');
//
// function logEventOb(e) {
// console.log(e);
// }
//
// mainContainer.addEventListener("click", logEventOb);
// var redBox = document.getElementById('box');
// redBox.addEventListener("click", function() {
// console.log(e);
// console.log("clicked red box");
// });
//
//
// function someFunction() {
// console.log();
// }
// Quick side note on event object
// function addEventListenerExample(eventType, someFunction) {
// console.log(eventType);
// // generate and event object
// var eventObject = {};
// someFunction(eventObject);
// }
//
// var someArr = [1, 2, 3];
//
// someArr.forEach(function(element) {
// console.log(element);
// });
//
// jQuery with anon function
// $('#container').click(function(e) {
// console.log(e);
// });
// jQuery with defined handler
// function logEventOb(e) {
// console.log(e);
// }
//
// $('#container').click(logEventOb);
// Double click and using "this" or "e.target"
// $('#box').dblclick(function() {
// $('#box').css('background', 'green');
// });
// $('p').dblclick(function(e) {
// console.log(this);
// console.log(e.target);
// $('p').css('color', 'blue');
// $(e.target).css('color', 'blue');
// $(this).css('color', 'red');
// });
// $('li').dblclick(function() {
// console.log(this);
// $(this).css("background", "yellow");
// });
// $('li').dblclick(function(e) {
// // console.log(e.target);
// $(e.target).css("background", "yellow");
// });
// Hover
//SINGLE FUNCTION
// $('.box').hover(function() {
// $(this).css('border-radius', '100px');
// });
// $('.box').hover(function() {
// var specialItemNode = document.getElementById('special-item');
// $(specialItemNode).css('display', 'none');
// });
//TWO FUNCTIONS
// $('.box').hover(function() {
// $(this).css('background', 'grey');
// }, function() {
// $(this).css('background', 'red');
// });
/* extra practice problems
- double clicking on the square makes it disappear
- clicking on a paragraph will change the text to 'Howdy!'
- hovering over the sub header makes the letters turn to uppercase while hovering over
*/
// });
</script>
</body>
</html>