Changeset 35776
- Timestamp:
- 2021-12-09T10:52:12+13:00 (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/model-interfaces-dev/atea/ocr/src/components/OcrImageDisplay.vue
r35775 r35776 33 33 } 34 34 35 this.$refs.magnifier.style.background = "url('" + newImage.src + "')"; 36 this.$refs.magnifier.style.backgroundSize = (newImage.width * this.magnifierZoom) + "px " + 37 (newImage.height * this.magnifierZoom) + "px"; 35 /** @type {HTMLDivElement} */ 36 const magnifier = this.$refs.magnifier; 37 const magWidth = newImage.width * this.magnifierZoom; 38 const magHeight = newImage.height * this.magnifierZoom; 39 40 magnifier.style.backgroundImage = `url('${newImage.src}')`; 41 magnifier.style.backgroundSize = `${magWidth}px ${magHeight}px`; 38 42 39 43 this.magnifierBounds = newImage.getBoundingClientRect(); … … 55 59 const magXCenter = magnifier.offsetWidth / 2; 56 60 const magYCenter = magnifier.offsetHeight / 2; 57 let { x, y } = getRelativeCursorPos(e);61 let { x, y } = this.getRelativeCursorPos(e, magContainerBounds); 58 62 59 63 // Calculate our screen-space bounds … … 81 85 magnifier.style.top = (y - magYCenter) + "px"; 82 86 83 const imageX = x - relImageLeft - magXCenter; 84 const imageY = y - relImageTop - magYCenter; 85 86 magnifier.style.backgroundPosition = "-" + (imageX * this.magnifierZoom) + "px -" + (imageY * this.magnifierZoom) + "px"; 87 88 /** 89 * Gets the position of the cursor relative to the magnifier's container. 90 * @param {MouseEvent} e The mouse event. 91 */ 92 function getRelativeCursorPos(e) { 93 let x = e.pageX - magContainerBounds.x; 94 let y = e.pageY - magContainerBounds.y; 95 96 // Consider any page scrolling 97 x = x - window.scrollX; 98 y = y - window.scrollY; 99 100 return { 101 x: x, 102 y: y 103 }; 104 } 87 // Calculate the offset for the magnified image 88 const imageX = x - relImageLeft - (magXCenter / this.magnifierZoom); 89 const imageY = y - relImageTop - (magYCenter / this.magnifierZoom); 90 91 // Convert the offset to valid CSS values 92 const actualX = imageX < 0 93 ? "0" 94 : `-${(imageX * this.magnifierZoom)}px` 95 96 const actualY = imageY < 0 97 ? "0" 98 : `-${(imageY * this.magnifierZoom)}px` 99 100 magnifier.style.backgroundPosition = `${actualX} ${actualY}` 101 }, 102 /** 103 * Gets the position of the cursor relative to a container. 104 * @param {MouseEvent} e The mouse event. 105 * @param {DOMRect} bounds The bounding container. 106 * @returns {{x: Number, y: Number}} The relative X and Y coordinate of the cursor. 107 */ 108 getRelativeCursorPos(e, bounds) { 109 let x = e.pageX - bounds.x; 110 let y = e.pageY - bounds.y; 111 112 // Consider any page scrolling 113 x = x - window.scrollX; 114 y = y - window.scrollY; 115 116 return { 117 x: x, 118 y: y 119 }; 105 120 } 106 121 }, … … 210 225 .magnifier { 211 226 position: absolute; 212 width: 1 50px;213 height: 1 50px;227 width: 175px; 228 height: 175px; 214 229 215 230 background-repeat: no-repeat; 216 231 border: 2px solid #000; 217 // cursor: none; 232 cursor: none; 233 border-radius: 40%; 218 234 } 219 235 </style>
Note:
See TracChangeset
for help on using the changeset viewer.