1
00:00:00,780 --> 00:00:06,510
All right so in the last video we looked it at event listener and we also took a look at the event object

2
00:00:06,520 --> 00:00:09,370
in some of the things that offers.

3
00:00:09,450 --> 00:00:12,240
Now what I want to do is look at certain mouse events.

4
00:00:12,250 --> 00:00:16,940
OK so we'll look at most events in this lecture and then in the next one we'll look at keyboard and

5
00:00:16,940 --> 00:00:18,350
input events.

6
00:00:18,360 --> 00:00:23,670
So first thing I want to do here is just create a couple of variables that point to selectors So let's

7
00:00:23,670 --> 00:00:25,030
get the clear button.

8
00:00:25,320 --> 00:00:34,320
So I'm going to call this variable clear beat and then set it to document Daut queries selector and

9
00:00:34,320 --> 00:00:39,820
it has a class of clear dash tasks.

10
00:00:39,840 --> 00:00:40,200
All right.

11
00:00:40,210 --> 00:00:42,940
Another thing I want to grab is the card.

12
00:00:43,170 --> 00:00:47,270
OK so the card is the entire thing.

13
00:00:47,610 --> 00:00:54,220
Everything that's within this border you can see has a class of card which is right here.

14
00:00:54,300 --> 00:00:57,180
So I'm going to say document Daut

15
00:01:00,720 --> 00:01:06,090
query selector and reward the class of card.

16
00:01:06,450 --> 00:01:06,840
OK.

17
00:01:06,850 --> 00:01:12,060
And the last thing I want is just this heading right here this task heading which is an H5.

18
00:01:12,360 --> 00:01:16,260
So I'm going to say Konst call this heading.

19
00:01:16,400 --> 00:01:25,140
Set it to document dot query selector and I will just grab it by its tag which is h 5.

20
00:01:25,140 --> 00:01:25,430
All right.

21
00:01:25,440 --> 00:01:29,040
So there's just a couple of things I want to do with these different elements.

22
00:01:29,280 --> 00:01:33,510
So let's create an event handler so

23
00:01:36,300 --> 00:01:37,610
we're going to create a function.

24
00:01:37,620 --> 00:01:41,740
And I'm just going to call this a run event.

25
00:01:42,420 --> 00:01:42,910
OK.

26
00:01:42,930 --> 00:01:47,800
And this run event is going to just take in the event object so.

27
00:01:48,330 --> 00:01:51,600
And then I want to just console log.

28
00:01:52,920 --> 00:02:00,330
I'll throw some template strings in here so some back ticks and I'm going to say event put this in caps

29
00:02:00,530 --> 00:02:08,100
will say event type and then remember we can grab these variable here or we can grab from the event

30
00:02:08,130 --> 00:02:09,900
object the type.

31
00:02:10,400 --> 00:02:17,190
OK so now I'm going to just use I'm going to do a click which we've already looked at but I'm going

32
00:02:17,190 --> 00:02:22,900
to put it in here anyway so click between dot and event listener.

33
00:02:23,400 --> 00:02:25,480
And we want to listen for a click.

34
00:02:25,710 --> 00:02:29,520
And when that click happens we're going to call run event.

35
00:02:30,010 --> 00:02:30,410
OK.

36
00:02:30,420 --> 00:02:32,340
So what do you think is going to happen here.

37
00:02:32,340 --> 00:02:35,580
I'm sure that you can figure this out it's pretty easy.

38
00:02:35,580 --> 00:02:40,600
So if I go ahead and click we're going to get event type and click.

39
00:02:40,620 --> 00:02:40,950
All right.

40
00:02:40,950 --> 00:02:47,260
So I just want to look at some of the other mouse events we also have a double click.

41
00:02:47,280 --> 00:02:57,090
So let's go ahead and take that clear button and let's add an event listener now for double click it's

42
00:02:57,090 --> 00:03:04,320
going to be DBIL click OK and then we'll just call run event and save.

43
00:03:04,320 --> 00:03:10,740
So now if we double click you'll see we get event type double click and I'm just going to comment these

44
00:03:11,250 --> 00:03:16,140
out as we go so that all that so that they don't keep adding up here.

45
00:03:16,290 --> 00:03:18,170
I just want to see the current event.

46
00:03:18,480 --> 00:03:22,410
So the next one is going to be most down.

47
00:03:22,410 --> 00:03:26,760
So I can actually just copy this.

48
00:03:27,000 --> 00:03:31,140
So we'll change just to mouse down and save.

49
00:03:31,170 --> 00:03:37,110
And now if I go and I just click and hold that's what fires off most down.

50
00:03:37,110 --> 00:03:39,660
All right click hold.

51
00:03:39,660 --> 00:03:41,240
I haven't let go of the mouse.

52
00:03:41,250 --> 00:03:43,780
That is the event mouse down.

53
00:03:43,810 --> 00:03:44,240
All right.

54
00:03:44,250 --> 00:03:49,890
And then at the same time we have mouse up which you can probably guess what it does it does the exact

55
00:03:49,890 --> 00:03:51,020
opposite.

56
00:03:51,060 --> 00:03:52,710
So it's common.

57
00:03:52,740 --> 00:03:57,510
So let's change this to mouse up and save.

58
00:03:57,510 --> 00:03:59,240
And now I'm going to click and hold.

59
00:03:59,370 --> 00:04:01,110
Notice that nothing has happened.

60
00:04:01,140 --> 00:04:04,820
When I let go that's when that event fires off.

61
00:04:04,830 --> 00:04:05,320
All right.

62
00:04:05,370 --> 00:04:11,150
Most down mouse up another event we have is mouse enter

63
00:04:15,520 --> 00:04:22,370
So let's go ahead and paste that in and let's do mouse enter.

64
00:04:24,740 --> 00:04:32,250
And save and you see that I'm just going to just drag into the button and there it is mouse enter.

65
00:04:32,310 --> 00:04:36,950
Actually no I'm going to put this on the card and not the button.

66
00:04:37,170 --> 00:04:40,300
So if I go into the card B get mouse enter.

67
00:04:40,320 --> 00:04:45,510
Now we also have mouse leave which is basically the opposite of that.

68
00:04:45,550 --> 00:04:49,110
So and the pace is soon in the same mouse we've

69
00:04:54,080 --> 00:05:00,040
And I'm going to keep going to keep mouse enter active as well so if we enter mouse enter if we go outside

70
00:05:00,040 --> 00:05:05,470
of the card because that's not working it's because I spelt this wrong.

71
00:05:05,830 --> 00:05:10,230
So we go in mouse enter we leave the card we get mouse leave.

72
00:05:10,390 --> 00:05:10,720
All right.

73
00:05:10,720 --> 00:05:18,640
Now in addition to mouse enter and mouse leave we have two other similar events which are mouse over

74
00:05:18,640 --> 00:05:20,310
and mouse out.

75
00:05:20,950 --> 00:05:23,790
So let's go ahead and change this to over

76
00:05:27,350 --> 00:05:29,350
and out.

77
00:05:29,360 --> 00:05:29,770
All right.

78
00:05:29,780 --> 00:05:37,640
So if I go in I just hover over the card you'll see we get mouse over and mouse enter.

79
00:05:37,820 --> 00:05:41,020
If I leave we get mouse out and mouse leaves.

80
00:05:41,020 --> 00:05:43,630
So what's the difference between these two.

81
00:05:43,940 --> 00:05:51,510
Well the difference is you'll see that if I go in and then I go over something else another element

82
00:05:51,540 --> 00:05:55,060
inside the card such as Clear tasks.

83
00:05:55,440 --> 00:06:02,850
You can see that we got mouse over and if I leave that we get mouse oh ok mouse over mouse out but Mouse

84
00:06:02,910 --> 00:06:07,360
enter and most leave are not firing off those only fire off when we go into that.

85
00:06:07,390 --> 00:06:14,910
The main element however mouse out and mouse over will fire off when you go into another element that's

86
00:06:14,910 --> 00:06:16,950
inside of that element.

87
00:06:16,950 --> 00:06:17,330
All right.

88
00:06:17,340 --> 00:06:18,490
Hopefully that makes sense.

89
00:06:18,500 --> 00:06:26,480
So whether it's this button or whether it's this list right here a list item mouse most out most overs

90
00:06:26,490 --> 00:06:28,070
going to keep on firing.

91
00:06:28,140 --> 00:06:28,760
OK.

92
00:06:29,010 --> 00:06:33,950
But mostly even mouse enter is only going to fire on the initial parent element.

93
00:06:33,960 --> 00:06:36,260
So that's the difference between these.

94
00:06:36,810 --> 00:06:38,750
All right so I'm going to comment those out

95
00:06:41,840 --> 00:06:43,010
OK.

96
00:06:43,350 --> 00:06:49,350
So the next thing I want to look at is mouse move.

97
00:06:49,350 --> 00:06:55,800
So it's go ahead and say let's put this on the card as well.

98
00:06:56,010 --> 00:06:58,850
So Sekhar dot our event listener

99
00:07:04,100 --> 00:07:08,150
most move you know we want to call run event.

100
00:07:08,840 --> 00:07:09,190
OK.

101
00:07:09,200 --> 00:07:11,500
So mouse move if I go in.

102
00:07:11,660 --> 00:07:14,690
It's just any movement inside of that element.

103
00:07:14,720 --> 00:07:15,160
OK.

104
00:07:15,160 --> 00:07:16,710
Anywhere in this card.

105
00:07:16,820 --> 00:07:21,770
If I move my mouse is firing that event off if I go outside and move it doesn't matter it's not going

106
00:07:21,770 --> 00:07:24,640
to fire it off it's just inside that element.

107
00:07:24,650 --> 00:07:24,980
All right.

108
00:07:24,980 --> 00:07:30,890
And you can use this for some really cool stuff when it comes to games things that are really really

109
00:07:30,890 --> 00:07:32,350
interactive.

110
00:07:32,360 --> 00:07:40,010
So what I want to do here is I'm going to make this heading I want this to display the coordinates of

111
00:07:40,010 --> 00:07:41,780
my mouse.

112
00:07:41,850 --> 00:07:48,680
You saw that we could access the E dot offset X and offset Y which gives us the coordinates of the mouse

113
00:07:48,680 --> 00:07:50,050
inside the element.

114
00:07:50,060 --> 00:07:54,500
So as this moves I want those elements to show up right here.

115
00:07:54,800 --> 00:08:02,500
I think it's a cool little exercise so we're going to take the headings because up here we we define

116
00:08:02,510 --> 00:08:11,900
heading as that age H5 right here and then we're going to say dog Bynner aged him now which just allows

117
00:08:11,900 --> 00:08:19,210
us to insert age T.M. into this element and then put in some actually we're going to put in our back

118
00:08:19,210 --> 00:08:25,010
ticks here and we're going to say I was put in an H5

119
00:08:29,700 --> 00:08:38,310
and then we'll do much I guess we could do text content since we're just going to keep it as an age

120
00:08:38,310 --> 00:08:38,640
5.

121
00:08:38,630 --> 00:08:46,440
There's really no sense in doing that but let's do most X and then we'll put in our variable that which

122
00:08:46,440 --> 00:09:02,610
will be e dot offset X Y and then we'll do mouse Y and we'll set this to the DOT offset y.

123
00:09:02,920 --> 00:09:08,050
OK so let's go ahead and save that and then let's go in and move our mouse around and you can see that

124
00:09:08,050 --> 00:09:13,850
the values are going to output in that age 5 which is kind of cool.

125
00:09:13,870 --> 00:09:14,220
All right.

126
00:09:14,220 --> 00:09:19,260
And like I said if you're building a game where you're controlling some kind of character with your

127
00:09:19,260 --> 00:09:26,420
mouse This is what you're going to use so that you know exactly where your character is in the game.

128
00:09:26,460 --> 00:09:26,790
All right.

129
00:09:26,790 --> 00:09:34,740
Another cool thing we could do is we can say document Daut body let's just get the body and we're going

130
00:09:34,740 --> 00:09:37,140
to say Daut style Daut

131
00:09:39,450 --> 00:09:47,160
background color and we're going to set that to a set of tactics.

132
00:09:47,160 --> 00:09:52,950
Now in CSSA you can change you can and you can make a color just you know standard color like red or

133
00:09:52,950 --> 00:10:00,420
blue or you can use a hexadecimal value or you can use an R.G. value which is red green blue and basically

134
00:10:00,420 --> 00:10:02,280
that takes three parameters.

135
00:10:02,280 --> 00:10:05,520
The first is going to be red second green third blue.

136
00:10:05,640 --> 00:10:11,130
And each one can be a value from 0 to 255.

137
00:10:11,130 --> 00:10:16,440
All right and then you get different different variations depending on those numbers.

138
00:10:16,440 --> 00:10:23,010
Now what I want to do is I want to take these two this these two offsets here from the event object

139
00:10:23,100 --> 00:10:26,040
and use those as parameters for red.

140
00:10:26,040 --> 00:10:36,090
We're going to use the x coordinate of the mouse and then for Green we'll use the Y and then for blue.

141
00:10:36,240 --> 00:10:38,250
We're just going to say 40.

142
00:10:38,250 --> 00:10:38,600
All right.

143
00:10:38,610 --> 00:10:44,070
So let's go ahead and save that and let's go in and start moving this around and you see that the background

144
00:10:44,070 --> 00:10:46,240
color just changes color.

145
00:10:46,430 --> 00:10:48,060
All right which is kind of cool.

146
00:10:48,180 --> 00:10:54,870
And I think gives you a good example of the different weird things you can do with this event with a

147
00:10:54,860 --> 00:10:56,130
mouse move.

148
00:10:56,640 --> 00:11:01,200
So that's going to be it for mouse events in the next video I want to get into events that have to do

149
00:11:01,200 --> 00:11:03,060
with forms in input.

