|
19 | 19 | .bubble-box{ |
20 | 20 | max-width: 20rem; /* You are likely to change it */ |
21 | 21 | position: absolute; |
| 22 | + right: -999px; |
22 | 23 | background: white; |
23 | 24 | border-radius: 4px; |
24 | 25 | padding: 4px; |
25 | 26 | word-break: break-all; |
26 | 27 | word-wrap: break-word; |
27 | 28 | box-shadow: 5px 5px 5px 3px rgba(0,0,0,0.2); |
28 | | - transform: translate(-50%, -4px); |
| 29 | + transform: translate(-50%, calc(-100% - 4px)); |
29 | 30 | } |
30 | 31 | .bubble-box::after{ |
31 | 32 | content: ''; |
|
103 | 104 | y: Math.max(l.y1, l.y2, l.y3, l.y4), |
104 | 105 | }; |
105 | 106 |
|
106 | | - /** |
107 | | - * 'convertToPageCoordinates()' is used to converts coordinate of a barcode location to the coordinate related to the document. |
108 | | - * Then we can place a div element according to the converted coordinate. |
109 | | - */ |
110 | | - const convertedP1 = scanner.convertToPageCoordinates(p1); |
111 | | - const convertedP2 = scanner.convertToPageCoordinates(p2); |
112 | | - |
113 | 107 | divInf = document.createElement("div"); |
114 | 108 | divInf.className = 'bubble-box'; |
115 | 109 | const bodyStyle = getComputedStyle(document.body); |
116 | 110 | if (bodyStyle.position === "static") { |
| 111 | + /** |
| 112 | + * 'convertToPageCoordinates()' is used to converts coordinate of a barcode location to the coordinate related to the document. |
| 113 | + * Then we can place a div element according to the converted coordinate. |
| 114 | + */ |
| 115 | + const convertedP1 = scanner.convertToPageCoordinates(p1); |
| 116 | + const convertedP2 = scanner.convertToPageCoordinates(p2); |
117 | 117 | Object.assign(divInf.style, { |
118 | 118 | left: `${(convertedP1.x + convertedP2.x) / 2}px`, |
119 | | - bottom: `${document.documentElement.clientHeight - convertedP1.y}px`, |
| 119 | + top: `${convertedP1.y}px`, |
120 | 120 | }); |
121 | 121 | } else { // if you set body `position` as `relative`, `absolute`, things can get complicated |
| 122 | + /** |
| 123 | + * 'convertToClientCoordinates()' is used to converts coordinate of a barcode location to the coordinate related to the viewport. |
| 124 | + * Then we can place a div element according to the converted coordinate. |
| 125 | + */ |
| 126 | + const convertedP1 = scanner.convertToClientCoordinates(p1); |
| 127 | + const convertedP2 = scanner.convertToClientCoordinates(p2); |
122 | 128 | const bodyRect = document.body.getBoundingClientRect(); |
123 | 129 | const bodyBorderLeft = parseFloat(bodyStyle.borderLeftWidth); |
124 | | - const bodyBorderBottom = parseFloat(bodyStyle.borderBottomWidth); |
| 130 | + const bodyBorderTop = parseFloat(bodyStyle.borderTopWidth); |
125 | 131 | Object.assign(divInf.style, { |
126 | 132 | left: `${(convertedP1.x + convertedP2.x) / 2 - bodyRect.left - bodyBorderLeft}px`, |
127 | | - bottom: `${bodyRect.bottom - convertedP1.y - bodyBorderBottom}px`, |
| 133 | + top: `${convertedP1.y - bodyRect.top - bodyBorderTop}px`, |
128 | 134 | }); |
129 | 135 | } |
130 | 136 | divInf.innerText = result.barcodeText; |
|
0 commit comments