Last active
June 11, 2020 10:53
-
-
Save CodHeK/8108db3a41fae6d48c16810a1719b334 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
THIS IS ONLY DONE ONCE | |
there-on we just keep changing the textContent of the $span. | |
*/ | |
const css = getComputedStyle($input); | |
const r = $input.getBoundingClientRect(); // to get the position, width & height of $input | |
const $span = document.createElement('span'); // our ghost span | |
$span.style.cssText = ` | |
width: ${r.width}px; | |
height: ${r.height}px; | |
left: ${r.left}px; | |
top: ${r.top}px; | |
z-index: -10; | |
opacity: 0.4; | |
position: absolute; | |
white-space: pre-wrap; | |
font-size: ${parseInt(css.fontSize)}px; | |
padding-left: ${parseInt(css.paddingLeft)}px; | |
padding-top: ${parseInt(css.paddingTop) + 1}px; // + 1 just to get a perfect alignment :p | |
`; | |
document.body.appendChild($span); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment