当前,代码在事件(更改后)上按预期工作,但是我需要运行(更改后)事件内的代码。
浮雕一旦初始化,我就需要运行逻辑。
$('.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)),但无法正常工作。