jquery - 加载时光滑的轮播调用事件
问题描述
目前,代码在事件(更改后)上按预期工作,但我需要运行(更改后)事件内部的代码。
一旦 slick 初始化,我需要运行逻辑。
$('.slick-wrapper').on('init', function(event, slick, currentSlide, nextSlide){
var $loginLogoutWideContainer = $('.row.hero-content'),
$loginLogoutWideContainerHeight = $loginLogoutWideContainer.height(),
$slideSelection = $(slick.$slides.get(currentSlide)),
$slideSelectionHeight = $slideSelection.height();
if (($slideSelectionHeight < $loginLogoutWideContainerHeight) && ($(window).width() > 991)) {
$slideSelection.height(($loginLogoutWideContainerHeight - 60) + 'px');
$slickOffersWrapper.slick('resize');
}
});
const slickSettings = {
dots: true,
autoplay: false,
autoplaySpeed: 5000,
fade: true,
cssEase: 'linear',
mobileFirst: true,
pauseOnDotsHover: true,
adaptiveHeight: true,
customPaging: function(slider, i) { //Custom paging is to replace the dots with numbers
var thumb = $(slider.$slides[i]).data();
return '<a>' + (i + 1) + '</a>';
},
responsive: [{
breakpoint: 1200,
settings: {
pauseOnDotsHover: false
}
}]
};
if ($('.slick-wrapper').children().length > 1) { //If slides are more than 1, construct slick
$('.slick-wrapper').slick(slickSettings); // Construct Slick
}
function minHeightSlickDesktopSize() {
var $loginLogoutWideContainerFixed = $('.row.hero-content');
if (($(window).width() > 991)) {
var $loginLogoutWideContainerFixedHeight = $loginLogoutWideContainerFixed.height();
$('.offers-block-wide .slick-list').css({
'min-height': ($loginLogoutWideContainerFixedHeight - 60) + 'px'
});
} else {
$('.slick-list').css('min-height', 'auto');
$('.slick-slide').css('height', 'auto');
}
};
minHeightSlickDesktopSize();
function assignHeightSlick() {
// Assign the height of the wide container to the slick slides to match the height
$('.slick-wrapper').on('afterChange', function(event, slick, currentSlide, nextSlide) {
var $loginLogoutWideContainer = $('.row.hero-content'),
$loginLogoutWideContainerHeight = $loginLogoutWideContainer.height(),
$slideSelection = $(slick.$slides.get(currentSlide)),
$slideSelectionHeight = $slideSelection.height();
if (($slideSelectionHeight < $loginLogoutWideContainerHeight) && ($(window).width() > 991)) {
$slideSelection.height(($loginLogoutWideContainerHeight) + 'px');
$slickOffersWrapper.slick('resize');
}
});
}
assignHeightSlick();
.row.hero-content {
height: 300px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.css"/>
<div class="parent">
<div class="row hero-content">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
<div class="slick-wrapper">
<div class="one">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</div>
<div class="two">It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages</div>
<div class="three">It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
</div>
</div>
光滑的旋转木马建成后,我需要调用“if”条件。它应该捕获第一张幻灯片并应用此逻辑。一旦回到第一张幻灯片,我的逻辑就起作用了。
我试图初始化(.on(init))但没有工作。
解决方案
推荐阅读
- sql - 如何在vbnet的另一个选项卡(tabcontrol)中显示datagridview
- reactjs - 带有反应选择的焦点小组
- c# - 如何在 Swagger 中为每个控制器创建一个新地址
- json - 如何从 json 文件中获取 id 并在视图 laravel 中显示以进行翻译
- google-cloud-platform - GCP VM 在 Web 和移动应用程序中显示不同的 CPU 使用率
- asp.net-web-api - 如何在 web api dot net core 中记录 http 请求和响应
- javascript - 在NodeJS中替换字符串中两个字符之间的字符的正则表达式是什么?请在下面查看我的问题。非常感谢
- reactjs - 使用 Chakra UI 为 MDX 文件设计样式
- reactjs - 如何在useState hook React中异步设置状态
- flutter - 警告:null-aware 操作的操作数 '??' 具有不包括 null 的“字符串”类型