• ARعربي
  • ENEnglish
  • ESEspañol
  • FAفارسی
  • FRFrançais
  • IDIndonesia
  • ITItaliano
  • JA日本語
  • KO한국어
  • RUРусский
  • TRTürkçe
  • UKУкраїнська
  • ZH简体中文

ما قصد داریم این پروژهٔ متن‌باز را در دسترس همهٔ مردم در سرتاسر دنیا قرار دهیم.

به ترجمهٔ محتوای این آموزش به زبان خودتان کمک کنید/a>.

    نقشه آموزش
    اشتراک گذاری
    • آموزش
    • مرورگر: Document، Eventها، رابط‌ها
    • جزئیات Eventها
    • Drag'n'Drop with mouse events
    بازگشت به درس
    این محتوا تنها در این زبان‌ها موجود است: English, Español, Français, Italiano, 日本語, Русский, Türkçe, Українська, 简体中文. لطفاً به ما

    Drag superheroes around the field

    اهمیت: 5

    This task can help you to check understanding of several aspects of Drag’n’Drop and DOM.

    Make all elements with class draggable – draggable. Like a ball in the chapter.

    Requirements:

    • Use event delegation to track drag start: a single event handler on document for mousedown.
    • If elements are dragged to top/bottom window edges – the page scrolls up/down to allow further dragging.
    • There is no horizontal scroll (this makes the task a bit simpler, adding it is easy).
    • Draggable elements or their parts should never leave the window, even after swift mouse moves.

    The demo is too big to fit it here, so here’s the link.

    دمو درون یک پنجره جدید

    باز کردن یک sandbox برای تمرین.

    To drag the element we can use position:fixed, it makes coordinates easier to manage. At the end we should switch it back to position:absolute to lay the element into the document.

    When coordinates are at window top/bottom, we use window.scrollTo to scroll it.

    More details in the code, in comments.

    باز کردن راه‌حل درون sandbox.

    • © 2007—2025  Ilya Kantor
    • دربارهٔ پروژه
    • تماس با ما