Skip to content

Commit 28a514a

Browse files
committed
minor
1 parent 92d6dc5 commit 28a514a

File tree

3 files changed

+13
-12
lines changed
  • 2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mouseleave

3 files changed

+13
-12
lines changed

2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mouseleave/1-behavior-nested-tooltip/task.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ importance: 5
44

55
# Improved tooltip behavior
66

7-
Write JavaScript that shows a tooltip over an element with the attribute `data-tooltip`.
7+
Write JavaScript that shows a tooltip over an element with the attribute `data-tooltip`. The value of this attribute should become the tooltip text.
88

99
That's like the task <info:task/behavior-tooltip>, but here the annotated elements can be nested. The most deeply nested tooltip is shown.
1010

11+
Only one tooltip may show up at the same time.
12+
1113
For instance:
1214

1315
```html
@@ -21,5 +23,3 @@ For instance:
2123
The result in iframe:
2224

2325
[iframe src="solution" height=300 border=1]
24-
25-
P.S. Hint: only one tooltip may show up at the same time.

2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mouseleave/2-hoverintent/solution.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ The algorithm looks simple:
33
1. Put `onmouseover/out` handlers on the element. Also can use `onmouseenter/leave` here, but they are less universal, won't work if we introduce delegation.
44
2. When a mouse cursor entered the element, start measuring the speed on `mousemove`.
55
3. If the speed is slow, then run `over`.
6-
4. Later if we're out of the element, and `over` was executed, run `out`.
6+
4. When we're going out of the element, and `over` was executed, run `out`.
77

8-
The question is: "How to measure the speed?"
8+
But how to measure the speed?
99

10-
The first idea would be: to run our function every `100ms` and measure the distance between previous and new coordinates. If it's small, then the speed is small.
10+
The first idea can be: run a function every `100ms` and measure the distance between previous and new coordinates. If it's small, then the speed is small.
1111

1212
Unfortunately, there's no way to get "current mouse coordinates" in JavaScript. There's no function like `getCurrentMouseCoordinates()`.
1313

14-
The only way to get coordinates is to listen to mouse events, like `mousemove`.
14+
The only way to get coordinates is to listen to mouse events, like `mousemove`, and take coordinates from the event object.
1515

16-
So we can set a handler on `mousemove` to track coordinates and remember them. Then we can compare them, once per `100ms`.
16+
So let's set a handler on `mousemove` to track coordinates and remember them. And then compare them, once per `100ms`.
1717

1818
P.S. Please note: the solution tests use `dispatchEvent` to see if the tooltip works right.

2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mouseleave/2-hoverintent/task.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ importance: 5
44

55
# "Smart" tooltip
66

7-
Write a function that shows a tooltip over an element only if the visitor moves the mouse *over it*, but not *through it*.
7+
Write a function that shows a tooltip over an element only if the visitor moves the mouse *to it*, but not *through it*.
88

9-
In other words, if the visitor moves the mouse on the element and stopped -- show the tooltip. And if they just moved the mouse through fast, then no need, who wants extra blinking?
9+
In other words, if the visitor moves the mouse to the element and stops there -- show the tooltip. And if they just moved the mouse through, then no need, who wants extra blinking?
1010

1111
Technically, we can measure the mouse speed over the element, and if it's slow then we assume that it comes "over the element" and show the tooltip, if it's fast -- then we ignore it.
1212

13-
Make a universal object `new HoverIntent(options)` for it. With `options`:
13+
Make a universal object `new HoverIntent(options)` for it.
1414

15+
Its `options`:
1516
- `elem` -- element to track.
16-
- `over` -- a function to call if the mouse is slowly moving over the element.
17+
- `over` -- a function to call if the mouse came to the element: that is, it moves slowly or stopped over it.
1718
- `out` -- a function to call when the mouse leaves the element (if `over` was called).
1819

1920
An example of using such object for the tooltip:

0 commit comments

Comments
 (0)