我正在爲我的項目使用滑動滑塊。當我登錄到應用程序時,所有項目都會隨箭頭一起出現在頁面上。轉盤只有在我刷新頁面後纔會出現。光滑滑塊只能在頁面刷新後才能正常工作
$(".best-sellers").not('.slick-initialized').slick({
dots: false,
infinite: false,
speed: 300,
slidesToShow: 5,
slidesToScroll: 5,
prevArrow: '<button type="button" class="btn-default slick-prev recentlyViewedControls"><i class="fa fa-2x fa-chevron-left" aria-hidden="true"></i></button>',
nextArrow: '<button type="button" class="btn-default slick-next recentlyViewedControls"><i class="fa fa-2x fa-chevron-right" aria-hidden="true"></i></button>'
});
}
HTML部分:
<div class="row recently-viewed-items" data-bind="foreach: cart.recentlyViewed()">
<div class="item col-sm-2 col-xs-6">
<a href="">
</a>
</div>
</div>
在foreach重複的元素。這些項目通過ajax調用。
'.not'函數返回與查詢不匹配的所有元素,但它是立即的。如果您打算等到css類'.slick-initialized'添加到您的HTML中,那麼您應該使用類似Observer的方法。看到這個:https://stackoverflow.com/questions/5525071/how-to-wait-until-an-element-exists。 –