Answer the question
In order to leave comments, you need to log in
Why can't I get value from styles?
In componentDidMount() I run a function to get the styles of the active slide.
handlerCalculateWidthSlides = () => {
let slideActive = this._slider.innerSlider.list.querySelector('.slick-current');
let stylesActiveSlide = getComputedStyle(slideActive);
console.log(stylesActiveSlide);
console.log(stylesActiveSlide.width);
};
console.log(slideActive);
// <div data-index="0" className="slick-slide slick-active slick-center slick-current" tabIndex="-1" aria-hidden="false" style="outline: none; width: 900px;">
console.log(slideActive.style.width)
// 20%
Answer the question
In order to leave comments, you need to log in
slideActive.style.width is the value given in the style attribute, and getComputedStyle returns the actual values computed by the browser.
Most likely, the library changes the value of width at runtime. Try to open the developer panel and see the values at a particular point in time there. There shouldn't be any magic.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question