(image)
| 90 | } |
| 91 | |
| 92 | const addImageGrabbing = (image) => { |
| 93 | image?.addEventListener('mousedown', (e) => { |
| 94 | if (!image.classList.contains("natural-zoom")) { |
| 95 | e.stopPropagation() |
| 96 | e.stopImmediatePropagation() |
| 97 | e.preventDefault() |
| 98 | |
| 99 | imageContainer.classList.add("grabbing") |
| 100 | state.start.x = e.pageX - imageContainer.offsetLeft |
| 101 | state.scroll.x = imageContainer.scrollLeft |
| 102 | state.start.y = e.pageY - imageContainer.offsetTop |
| 103 | state.scroll.y = imageContainer.scrollTop |
| 104 | } |
| 105 | }) |
| 106 | |
| 107 | image?.addEventListener('mouseup', stopGrabbing) |
| 108 | image?.addEventListener('mouseleave', stopGrabbing) |
| 109 | image?.addEventListener('mousemove', (e) => { |
| 110 | if (imageContainer.classList.contains("grabbing")) { |
| 111 | e.stopPropagation() |
| 112 | e.stopImmediatePropagation() |
| 113 | e.preventDefault() |
| 114 | |
| 115 | // Might need to increase this multiplier based on the image size to window size ratio |
| 116 | // The default 1:1 is pretty slow |
| 117 | const multiplier = 1.0 |
| 118 | |
| 119 | const deltaX = e.pageX - imageContainer.offsetLeft - state.start.x |
| 120 | imageContainer.scrollLeft = state.scroll.x - (deltaX * multiplier) |
| 121 | const deltaY = e.pageY - imageContainer.offsetTop - state.start.y |
| 122 | imageContainer.scrollTop = state.scroll.y - (deltaY * multiplier) |
| 123 | } |
| 124 | }) |
| 125 | } |
| 126 | |
| 127 | const clear = () => { |
| 128 | imageContainer.innerHTML = "" |
no test coverage detected