-
Notifications
You must be signed in to change notification settings - Fork 182
Moving the mouse #620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Moving the mouse #620
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b85cab0
2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mousel…
dolgachio c493c5c
2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mousel…
dolgachio f02c212
2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mousel…
dolgachio 7653c34
2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mousel…
dolgachio 8626b82
2-ui/3-event-details/3-mousemove-mouseover-mouseout-mouseenter-mousel…
dolgachio d7052eb
Merge branch 'javascript-tutorial:master' into master
dolgachio 3581cab
Apply suggestions from code review
dolgachio c7fe06b
Apply suggestions from code review
dolgachio 6b02e54
Apply suggestions from code review
dolgachio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 11 additions & 11 deletions
22
.../3-mousemove-mouseover-mouseout-mouseenter-mouseleave/2-hoverintent/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
|
||
The algorithm looks simple: | ||
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. | ||
2. When a mouse cursor entered the element, start measuring the speed on `mousemove`. | ||
3. If the speed is slow, then run `over`. | ||
4. When we're going out of the element, and `over` was executed, run `out`. | ||
Алгоритм виглядає просто: | ||
1. Додайте обробники `onmouseover/out` на елемент. Тут також можна використовувати `onmouseenter/leave`, але вони менш універсальні, і не працюватимуть, якщо ми використаємо делегування подій. | ||
2. Коли вказівник миші увійшов на елемент, почніть вимірювати швидкість на `mousemove`. | ||
3. Якщо швидкість низька, то запускаємо `over`. | ||
4. Коли вказівник виходить за межі елемента, і `over` закінчила свою роботу, запускаємо `out`. | ||
|
||
But how to measure the speed? | ||
Але як виміряти швидкість? | ||
|
||
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. | ||
Перша ідея може бути такою: запускати функцію кожні `100ms` і вимірювати відстань між попередньою та новою координатами. Якщо відстань маленька, то швидкість невелика. | ||
|
||
Unfortunately, there's no way to get "current mouse coordinates" in JavaScript. There's no function like `getCurrentMouseCoordinates()`. | ||
На жаль, у JavaScript немає способу отримати поточні координати вказівника миші. Немає таких функцій, як `getCurrentMouseCoordinates()`. | ||
|
||
The only way to get coordinates is to listen for mouse events, like `mousemove`, and take coordinates from the event object. | ||
Єдиний спосіб отримати координати -- в обробнику подій миші, наприклад `mousemove`, і брати координати з об’єкта події. | ||
|
||
So let's set a handler on `mousemove` to track coordinates and remember them. And then compare them, once per `100ms`. | ||
Отже, давайте додамо обробник на `mousemove`, де відстежемо і запам'ятаємо поточні координати. А далі будемо порівнювати їх раз на `100ms`. | ||
|
||
P.S. Please note: the solution tests use `dispatchEvent` to see if the tooltip works right. | ||
P.S. Зверніть увагу: тести рішення використовують `dispatchEvent`, щоб перевірити, чи підказка працює правильно. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.