Skip to content

Commit 7c45c30

Browse files
committed
getEmSize had wrong Syntax for 'getComputedStyle'
• The function getEmSize had a wrong Syntax for 'getComputedStyle', the 2nd parameter is only for pseudo selectors and it will return all styles, see [docs](https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle?redirectlocale=en-US&redirectslug=DOM%2Fwindow.getComputedStyle) • The function convertToPx did not work for floats, I guess ... E.g. `1.8rem`'s units became '.8rem' and so the switch failed... Corrected both.
1 parent deea2e7 commit 7c45c30

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/ElementQueries.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
if (!element) {
3232
element = document.documentElement;
3333
}
34-
var fontSize = getComputedStyle(element, 'fontSize');
34+
var fontSize = window.getComputedStyle(element, null).fontSize;
3535
return parseFloat(fontSize) || 16;
3636
}
3737

@@ -44,7 +44,8 @@
4444
* @returns {*}
4545
*/
4646
function convertToPx(element, value) {
47-
var units = value.replace(/[0-9]*/, '');
47+
var numbers = value.split(/\d/);
48+
var units = numbers[numbers.length-1];
4849
value = parseFloat(value);
4950
switch (units) {
5051
case "px":

0 commit comments

Comments
 (0)