H.H*_*ain 5 javascript responsive-design ecmascript-6 reactjs react-slick
我已经为我的网站实现了 React Slick Slider,它适用于桌面视图并相应地采用适当的宽度,但如果我切换到响应式视图,容器的宽度不正确并且看起来全部扭曲。
我尝试用 CSS 修复它,给slick-track
div 设置 100% 宽度,但没有任何效果。
以下是容器:slick-track,下面是添加的内联 CSS:
width: 2.14748e+08px;
opacity: 1;
transform: translate3d(-8.05305e+07px, 0px, 0px);
Run Code Online (Sandbox Code Playgroud)
以下是我在组件中初始化滑块的方式:
const settings = {
dots: false,
infinite: true,
speed: 500,
cssEase: 'linear',
slidesToShow: this.props.data && this.props.data.upSell && this.props.data.upSell.length>=5?6:this.props.data&& this.props.data.upSell && this.props.data.upSell.length,
rtl: rtl === "en" ? false : true,
slidesToScroll: 1,
asNavFor: null,
arrows: false,
initialSlide: rtl==="en"?0:2,
responsive: [
{
breakpoint: 768,
settings: {
slidesToShow: 2,
slidesToScroll: 1,
infinite: true,
initialSlide: rtl==="en"?0:3,
dots: false
}
}
]
};
Run Code Online (Sandbox Code Playgroud)
下面是循环中的 HTML 结构示例:
<Slider className="mx-4" {...settings} ref={c => (this.slider = c)}>
<div class="rtl product-item" tabindex="-1" style="width: 100%; display: inline-block;">
<div class="product-shop-top">
<a href="#"><img src="" alt="" class="product-img"></a>
</div>
<div class="product-item-details">
<h5><a href="#">Product Name</a></h5>
<div class="price-wrapper">
<div class="price-box"><span class="special-price">65</span></div>
</div>
</div>
<div class="buynow-block asas"><button type="button" title="Add to Cart" class="action tocart primary"> </button><a class="towishlist">Add to Wishlist</a></div>
</div>
</Slider>
Run Code Online (Sandbox Code Playgroud)
我想要连续 2 列用于响应式光滑滑块。
最后我找到了问题所在,滑块的容器与页面上其他元素位于同一行内,这导致滑块无法计算宽度的问题。之前的结构是这样的:
<div classname="row">
<div classname="elementone"></div>
<div classname="elementtwo"></div>
<div classname="slider"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
所以我将滑块移到行外,现在工作正常。
归档时间: |
|
查看次数: |
15412 次 |
最近记录: |