yskang

threejs-viewer-18

May 2nd, 2021
709
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. init() {
  2.     // ... other code snippet
  3.  
  4.     this.buildDragEvent();
  5. }
  6.  
  7. // ... other code snippet
  8. // ref: https://www.w3schools.com/howto/howto_js_draggable.asp
  9. buildDragEvent() {
  10.     const panel = this;
  11.     let pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
  12.     if (panel.titlebar) {
  13.         // if present, the header is where you move the DIV from:
  14.         panel.titlebar.addEventListener('mousedown', dragMouseDown);
  15.     } else {
  16.         // otherwise, move the DIV from anywhere inside the DIV:
  17.         panel.container.addEventListener('mousedown', dragMouseDown);
  18.     }
  19.  
  20.     function dragMouseDown(e) {
  21.         e = e || window.event;
  22.         e.preventDefault();
  23.         // get the mouse cursor position at startup:
  24.         pos3 = e.clientX;
  25.         pos4 = e.clientY;
  26.         document.addEventListener('mouseup', closeDragElement);
  27.         // call a function whenever the cursor moves:
  28.         document.addEventListener('mousemove', elementDrag);
  29.     }
  30.  
  31.     function elementDrag(e) {
  32.         e = e || window.event;
  33.         e.preventDefault();
  34.         // calculate the new cursor position:
  35.         pos1 = pos3 - e.clientX;
  36.         pos2 = pos4 - e.clientY;
  37.         pos3 = e.clientX;
  38.         pos4 = e.clientY;
  39.         // set the element's new position:
  40.         panel.container.style.top = (panel.container.offsetTop - pos2) + "px";
  41.         panel.container.style.left = (panel.container.offsetLeft - pos1) + "px";
  42.     }
  43.  
  44.     function closeDragElement() {
  45.         // stop moving when mouse button is released:
  46.         document.removeEventListener('mouseup', closeDragElement);
  47.         document.removeEventListener('mousemove', elementDrag);
  48.     }
  49. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×