- Notifications
You must be signed in to change notification settings - Fork179
Drag'n'Drop with mouse events#322
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
13 commits Select commitHold shift + click to select a range
833a6cd
Finished translate "Dynamic imports" article
b4158fc
Revert "Finished translate "Dynamic imports" article"
c843f3d
added some translations and provided corrections
AntonBurchak8c95048
Apply suggestions from code review
AntonBurchak98e602d
Update soccer.js
AntonBurchakb966c14
Update index.html
AntonBurchakacaea59
Update task.md
AntonBurchake0403bd
Update index.html
AntonBurchak016297c
Update index.html
AntonBurchakea5b2b1
Update index.html
AntonBurchak016b25d
Apply suggestions from code review
AntonBurchakf747b5f
Update article.md
AntonBurchakb90a49a
Update article.md
AntonBurchakFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
6 changes: 3 additions & 3 deletions2-ui/3-event-details/4-mouse-drag-and-drop/1-slider/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,5 +1,5 @@ | ||
Як можна бачити з `HTML/CSS`, слайдер -- це`<div>`, з кольровим фоном, всередині якого знаходиться інший`<div>`, оформлений як бігунок, з`position:relative`. | ||
Використаємо для його позиціювання`position:relative`,тобто координати встановлюються не абсолютні (`position: absolute`), а відносно батьківського елементу, бо це зручніше. | ||
І далі реалізуємоDrag'n'Dropтільки по горизонталі, з обмеженням по ширині. |
6 changes: 3 additions & 3 deletions2-ui/3-event-details/4-mouse-drag-and-drop/1-slider/solution.view/index.html
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
2 changes: 1 addition & 1 deletion2-ui/3-event-details/4-mouse-drag-and-drop/1-slider/source.view/index.html
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 |
---|---|---|
@@ -13,7 +13,7 @@ | ||
</div> | ||
<script> | ||
// ...ваш код... | ||
</script> | ||
</body> | ||
12 changes: 6 additions & 6 deletions2-ui/3-event-details/4-mouse-drag-and-drop/1-slider/task.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
6 changes: 3 additions & 3 deletions2-ui/3-event-details/4-mouse-drag-and-drop/2-drag-heroes/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,5 +1,5 @@ | ||
Щоб перетягнути елемент, ми можемо використовувати`position:fixed`,це робить управління координатами простішим. Після завершення слід переключитися назад на`position:absolute`, щоб елемент залишився частиною сторінки. | ||
Коли координати знаходяться у верхній/нижній частині вікна, ми використовуємо `window.scrollTo`для прокрутки. | ||
Деталі рішення розписані в коментарях у коді. |
24 changes: 12 additions & 12 deletions2-ui/3-event-details/4-mouse-drag-and-drop/2-drag-heroes/solution.view/index.html
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
2 changes: 1 addition & 1 deletion2-ui/3-event-details/4-mouse-drag-and-drop/2-drag-heroes/solution.view/soccer.css
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
46 changes: 23 additions & 23 deletions2-ui/3-event-details/4-mouse-drag-and-drop/2-drag-heroes/solution.view/soccer.js
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 | ||||
---|---|---|---|---|---|---|
@@ -24,9 +24,9 @@ document.addEventListener('mousedown', function(event) { | ||||||
moveAt(event.clientX, event.clientY); | ||||||
} | ||||||
//на початку переміщення елемента: | ||||||
//зберегаємо місце кліку по елементу | ||||||
//перемикаємо позиціонування елемента (position:fixed) і рухаємо елемент | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Suggested change
| ||||||
function startDrag(element, clientX, clientY) { | ||||||
if(isDragging) { | ||||||
return; | ||||||
@@ -45,7 +45,7 @@ document.addEventListener('mousedown', function(event) { | ||||||
moveAt(clientX, clientY); | ||||||
}; | ||||||
//перемикаємося назад на абсолютні координати щоб закріпити елемент відносно документа | ||||||
function finishDrag() { | ||||||
if(!isDragging) { | ||||||
return; | ||||||
@@ -61,49 +61,49 @@ document.addEventListener('mousedown', function(event) { | ||||||
} | ||||||
function moveAt(clientX, clientY) { | ||||||
//обчислюємо нові координати (відносно вікна) | ||||||
let newX = clientX - shiftX; | ||||||
let newY = clientY - shiftY; | ||||||
//перевіряємо, чи не виходять нові координати за нижній край вікна: | ||||||
let newBottom = newY + dragElement.offsetHeight; //нові координати | ||||||
//виходять за межі вікна? прокручуємо сторінку | ||||||
if (newBottom > document.documentElement.clientHeight) { | ||||||
//координата нижнього краю документа щодо вікна | ||||||
let docBottom = document.documentElement.getBoundingClientRect().bottom; | ||||||
//прокрутка документа на10pxвниз має проблему -- | ||||||
//він може прокрутити документ за його межі, | ||||||
//тому використовуємоMath.min (відстань до кінця, 10) | ||||||
let scrollY = Math.min(docBottom - newBottom, 10); | ||||||
//обчислення можуть бути не зовсім точні -- трапляються помилки при округленні, | ||||||
//які призводять до негативного значенням прокрутки. Відфільтруємо їх: | ||||||
if (scrollY < 0) scrollY = 0; | ||||||
window.scrollBy(0, scrollY); | ||||||
//швидке переміщення миші може помістити курсор за межі документа вниз | ||||||
//якщо це сталося - | ||||||
//обмежуємо нове значення Yмаксимально можливим, виходячи з розміру документа: | ||||||
newY = Math.min(newY, document.documentElement.clientHeight - dragElement.offsetHeight); | ||||||
} | ||||||
//перевіряємо, чи не переходять нові координати за верхній край вікна (за схожим алгоритмом) | ||||||
if (newY < 0) { | ||||||
// scroll up | ||||||
let scrollY = Math.min(-newY, 10); | ||||||
if (scrollY < 0) scrollY = 0; //перевіряємо помилки точності | ||||||
window.scrollBy(0, -scrollY); | ||||||
//швидке переміщення миші може помістити курсор за межі документа зверху | ||||||
newY = Math.max(newY, 0); // newYне може бути менше нуля | ||||||
} | ||||||
//обмежимо newX розмірами вікна | ||||||
//згідно з умовою, горизонтальна прокрутка відсутня, тому це не складно: | ||||||
if (newX < 0) newX = 0; | ||||||
if (newX > document.documentElement.clientWidth - dragElement.offsetWidth) { | ||||||
newX = document.documentElement.clientWidth - dragElement.offsetWidth; | ||||||
24 changes: 12 additions & 12 deletions2-ui/3-event-details/4-mouse-drag-and-drop/2-drag-heroes/source.view/index.html
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
2 changes: 1 addition & 1 deletion2-ui/3-event-details/4-mouse-drag-and-drop/2-drag-heroes/source.view/soccer.css
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
2 changes: 1 addition & 1 deletion2-ui/3-event-details/4-mouse-drag-and-drop/2-drag-heroes/source.view/soccer.js
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 +1 @@ | ||
//Ваш код |
18 changes: 9 additions & 9 deletions2-ui/3-event-details/4-mouse-drag-and-drop/2-drag-heroes/task.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
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
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.