diff --git a/mouseevents/README.md b/mouseevents/README.md new file mode 100644 index 0000000..ff1cb26 --- /dev/null +++ b/mouseevents/README.md @@ -0,0 +1,5 @@ +Examples: + +* [ClickNDrag program](https://mdn.github.com/dom-examples/mouseevents/Click_N_Drag.html). This illustrates clicking and dragging of objects on a web page, without the Drag & Drop API. + + diff --git a/mouseevents/click-and-drag/Click_N_Drag.css b/mouseevents/click-and-drag/Click_N_Drag.css new file mode 100644 index 0000000..6d1f004 --- /dev/null +++ b/mouseevents/click-and-drag/Click_N_Drag.css @@ -0,0 +1,57 @@ +/* without these, the page ends after the content. + I want to drag all over the page. */ +html, body, main.arena { + width: 100%; + height: 100%; +} + +html { + overflow: hidden; + background: white; +} + +/* wrapper for either a physicist or a slot */ +li { + list-style-type: none; + width: 400px; + padding: 2px; + margin: 13px; + border-radius: 5px; +} + +/* a target for mousedown */ +.physicist { + cursor: grab; // tells user they can grab it + line-height: 20px; + background-color: #488; + border: 4px outset #aca; + color: #fff; + text-align: center; +} + +/* the physicist that the user is dragging around, after user has clicked to drag */ +.physicist.ghost { + position: absolute; + background-color: #266; + opacity: 0.7; /* want to be able to see hilited slot underneath */ + pointer-events: none; /* so pointer events go thru to slot */ +} + +/* physicist, hidden after it's been picked up and only the ghost is visible */ +.physicist.original { + visibility: hidden; +} + +/* where to drag a physicist */ +.slot { + height: 15px; + background-color: #dfd; + border: 4px inset #aca; + /*color: black;*/ +} + +.slot.targeted { + /* When user moves ghost over a slot. A BIG change in appearance; + this only happens for a fraction of a second and is otherwise hard to see */ + background-color: #f80; +} diff --git a/mouseevents/click-and-drag/Click_N_Drag.html b/mouseevents/click-and-drag/Click_N_Drag.html new file mode 100644 index 0000000..2065dfc --- /dev/null +++ b/mouseevents/click-and-drag/Click_N_Drag.html @@ -0,0 +1,36 @@ + + + + + + + + + + +
+

Click and Drag demo, using mouse events. + Drag a physicist's name into one of the green slots to rearrange

+ +
+ + + + + diff --git a/mouseevents/click-and-drag/Click_N_Drag.js b/mouseevents/click-and-drag/Click_N_Drag.js new file mode 100644 index 0000000..2fe87d8 --- /dev/null +++ b/mouseevents/click-and-drag/Click_N_Drag.js @@ -0,0 +1,174 @@ + +let physicists = ['Noether', 'Dirac', 'Bohr', 'Curie', 'Pauli']; + +// yes, using globals is a bad idea, in general. But in this case, there's only +// one mouse, so there'll never be two users of these variables at once. +// The arena is the whole area the user can drag around in. +// all these are element refs. +let arenaElement; +let arenaUl; // the