|
17 | 17 | </title> |
18 | 18 | <style> |
19 | 19 | .bubble-box{ |
| 20 | + max-width: 20rem; /* You are likely to change it */ |
20 | 21 | position: absolute; |
21 | 22 | background: white; |
22 | 23 | border-radius: 4px; |
23 | 24 | padding: 4px; |
24 | 25 | word-break: break-all; |
25 | 26 | word-wrap: break-word; |
26 | 27 | box-shadow: 5px 5px 5px 3px rgba(0,0,0,0.2); |
| 28 | + transform: translateX(-50%); |
27 | 29 | } |
28 | 30 | .bubble-box::after{ |
29 | 31 | content: ''; |
|
110 | 112 |
|
111 | 113 | divInf = document.createElement("div"); |
112 | 114 | divInf.className = 'bubble-box'; |
113 | | - // define width of the bubble box |
114 | | - const divInfWidth = "20rem"; |
115 | | - divInf.style.width = divInfWidth; |
116 | 115 | const divInfVerticalOffset = 4; //px |
117 | 116 | const bodyStyle = getComputedStyle(document.body); |
118 | 117 | if (bodyStyle.position === "static") { |
119 | 118 | Object.assign(divInf.style, { |
120 | | - left: `calc(${(convertedP1.x + convertedP2.x) / 2}px - ${divInfWidth} / 2)`, |
| 119 | + left: `${(convertedP1.x + convertedP2.x) / 2}px`, |
121 | 120 | bottom: `${document.documentElement.clientHeight - convertedP1.y + divInfVerticalOffset}px`, |
122 | 121 | }); |
123 | 122 | } else { // if you set body `position` as `relative`, `absolute`, things can get complicated |
124 | 123 | const bodyRect = document.body.getBoundingClientRect(); |
125 | 124 | const bodyBorderLeft = parseFloat(bodyStyle.borderLeftWidth); |
126 | 125 | const bodyBorderBottom = parseFloat(bodyStyle.borderBottomWidth); |
127 | | - const bodyPaddingLeft = parseFloat(bodyStyle.paddingLeft); |
128 | | - const bodyPaddingBottom = parseFloat(bodyStyle.paddingBottom); |
129 | 126 | Object.assign(divInf.style, { |
130 | | - left: `calc(${(convertedP1.x + convertedP2.x) / 2 - bodyRect.left - bodyBorderLeft - bodyPaddingLeft}px - ${divInfWidth} / 2)`, |
131 | | - bottom: `${bodyRect.bottom - convertedP1.y - bodyBorderBottom - bodyPaddingBottom + divInfVerticalOffset}px`, |
| 127 | + left: `${(convertedP1.x + convertedP2.x) / 2 - bodyRect.left - bodyBorderLeft}px`, |
| 128 | + bottom: `${bodyRect.bottom - convertedP1.y - bodyBorderBottom + divInfVerticalOffset}px`, |
132 | 129 | }); |
133 | 130 | } |
134 | 131 | divInf.innerText = result.barcodeText; |
|
0 commit comments