Skip to content

Commit

Permalink
fix(core): use getComputedStyle helper
Browse files Browse the repository at this point in the history
fixes #4337
  • Loading branch information
nolimits4web committed Mar 17, 2021
1 parent 75cfdb9 commit 9698e58
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/components/core/update/updateSlides.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getWindow } from 'ssr-window';
import { extend } from '../../../utils/utils';

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

const window = getWindow();
const params = swiper.params;

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

if (params.slidesPerView === 'auto') {
const slideStyles = window.getComputedStyle(slide[0], null);
const slideStyles = getComputedStyle(slide[0]);
const currentTransform = slide[0].style.transform;
const currentWebKitTransform = slide[0].style.webkitTransform;
if (currentTransform) {
Expand Down
28 changes: 26 additions & 2 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,28 @@ function nextTick(callback, delay = 0) {
function now() {
return Date.now();
}
function getComputedStyle(el) {
const window = getWindow();
let style;
if (window.getComputedStyle) {
style = window.getComputedStyle(el, null);
}
if (!style && el.currentStyle) {
style = el.currentStyle;
}
if (!style) {
style = el.style;
}

return style;
}
function getTranslate(el, axis = 'x') {
const window = getWindow();
let matrix;
let curTransform;
let transformMatrix;

const curStyle = window.getComputedStyle(el, null);
const curStyle = getComputedStyle(el, null);

if (window.WebKitCSSMatrix) {
curTransform = curStyle.transform || curStyle.webkitTransform;
Expand Down Expand Up @@ -110,4 +125,13 @@ function bindModuleMethods(instance, obj) {
});
}

export { deleteProps, nextTick, now, getTranslate, isObject, extend, bindModuleMethods };
export {
deleteProps,
nextTick,
now,
getTranslate,
isObject,
extend,
bindModuleMethods,
getComputedStyle,
};

0 comments on commit 9698e58

Please sign in to comment.