Skip to content

Commit 9698e58

Browse files
committed
fix(core): use getComputedStyle helper
fixes #4337
1 parent 75cfdb9 commit 9698e58

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

src/components/core/update/updateSlides.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { getWindow } from 'ssr-window';
21
import { extend } from '../../../utils/utils';
32

43
export default function updateSlides() {
@@ -23,7 +22,6 @@ export default function updateSlides() {
2322
return parseFloat(node.getPropertyValue(getDirectionLabel(label)) || 0);
2423
};
2524

26-
const window = getWindow();
2725
const params = swiper.params;
2826

2927
const { $wrapperEl, size: swiperSize, rtlTranslate: rtl, wrongRTL } = swiper;
@@ -151,7 +149,7 @@ export default function updateSlides() {
151149
if (slide.css('display') === 'none') continue; // eslint-disable-line
152150

153151
if (params.slidesPerView === 'auto') {
154-
const slideStyles = window.getComputedStyle(slide[0], null);
152+
const slideStyles = getComputedStyle(slide[0]);
155153
const currentTransform = slide[0].style.transform;
156154
const currentWebKitTransform = slide[0].style.webkitTransform;
157155
if (currentTransform) {

src/utils/utils.js

+26-2
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,28 @@ function nextTick(callback, delay = 0) {
2121
function now() {
2222
return Date.now();
2323
}
24+
function getComputedStyle(el) {
25+
const window = getWindow();
26+
let style;
27+
if (window.getComputedStyle) {
28+
style = window.getComputedStyle(el, null);
29+
}
30+
if (!style && el.currentStyle) {
31+
style = el.currentStyle;
32+
}
33+
if (!style) {
34+
style = el.style;
35+
}
36+
37+
return style;
38+
}
2439
function getTranslate(el, axis = 'x') {
2540
const window = getWindow();
2641
let matrix;
2742
let curTransform;
2843
let transformMatrix;
2944

30-
const curStyle = window.getComputedStyle(el, null);
45+
const curStyle = getComputedStyle(el, null);
3146

3247
if (window.WebKitCSSMatrix) {
3348
curTransform = curStyle.transform || curStyle.webkitTransform;
@@ -110,4 +125,13 @@ function bindModuleMethods(instance, obj) {
110125
});
111126
}
112127

113-
export { deleteProps, nextTick, now, getTranslate, isObject, extend, bindModuleMethods };
128+
export {
129+
deleteProps,
130+
nextTick,
131+
now,
132+
getTranslate,
133+
isObject,
134+
extend,
135+
bindModuleMethods,
136+
getComputedStyle,
137+
};

0 commit comments

Comments
 (0)