Fix slider init
This commit is contained in:
@@ -17,10 +17,14 @@ $(function () {
|
||||
if (
|
||||
!$container.length ||
|
||||
!$paginationEl.length ||
|
||||
!$textBox.length ||
|
||||
typeof Swiper === 'undefined'
|
||||
)
|
||||
return
|
||||
|
||||
// -----------------------------
|
||||
// TITLES
|
||||
// -----------------------------
|
||||
var titles = []
|
||||
try {
|
||||
titles = JSON.parse($root.attr('data-titles') || '[]')
|
||||
@@ -28,23 +32,61 @@ $(function () {
|
||||
titles = []
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
// SET SLIDE HTML BY INDEX
|
||||
// -----------------------------
|
||||
function setHtmlByIndex(idx) {
|
||||
var $slide = $container.find('.swiper-slide').eq(idx)
|
||||
var html =
|
||||
$slide.find('.customdevslider-swiper__slide-html').first().html() || ''
|
||||
$slide
|
||||
.find('.customdevslider-swiper__slide-html')
|
||||
.first()
|
||||
.html() || ''
|
||||
|
||||
$textBox.html(html)
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
// CALC MAX TEXT HEIGHT
|
||||
// -----------------------------
|
||||
function setMaxTextHeight() {
|
||||
var maxHeight = 0
|
||||
var originalHtml = $textBox.html()
|
||||
|
||||
$container.find('.swiper-slide').each(function () {
|
||||
var html = $(this)
|
||||
.find('.customdevslider-swiper__slide-html')
|
||||
.first()
|
||||
.html()
|
||||
|
||||
if (!html) return
|
||||
|
||||
$textBox.html(html)
|
||||
$textBox.css('height', 'auto')
|
||||
|
||||
var h = $textBox.outerHeight(true)
|
||||
if (h > maxHeight) maxHeight = h
|
||||
})
|
||||
|
||||
$textBox.html(originalHtml)
|
||||
$textBox.height(maxHeight)
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
// INIT SWIPER
|
||||
// -----------------------------
|
||||
var swiper = new Swiper($container[0], {
|
||||
loop: true,
|
||||
speed: 600,
|
||||
|
||||
autoplay: {
|
||||
delay: 5000,
|
||||
},
|
||||
|
||||
// fade
|
||||
effect: 'fade',
|
||||
fadeEffect: { crossFade: true },
|
||||
fadeEffect: {
|
||||
crossFade: true,
|
||||
},
|
||||
|
||||
pagination: {
|
||||
el: $paginationEl[0],
|
||||
@@ -70,29 +112,7 @@ $(function () {
|
||||
},
|
||||
})
|
||||
|
||||
// fallback
|
||||
setHtmlByIndex(0)
|
||||
})
|
||||
|
||||
function setMaxTextHeight() {
|
||||
var maxHeight = 0
|
||||
var originalHtml = $textBox.html()
|
||||
|
||||
$container.find('.swiper-slide').each(function () {
|
||||
var html = $(this)
|
||||
.find('.customdevslider-swiper__slide-html')
|
||||
.first()
|
||||
.html()
|
||||
|
||||
if (!html) return
|
||||
|
||||
$textBox.html(html)
|
||||
$textBox.css('height', 'auto')
|
||||
|
||||
var h = $textBox.outerHeight(true)
|
||||
if (h > maxHeight) maxHeight = h
|
||||
})
|
||||
|
||||
$textBox.html(originalHtml)
|
||||
$textBox.height(maxHeight)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
</a>
|
||||
{/if}
|
||||
|
||||
{* ВАЖЛИВО: зберігаємо HTML структуру тексту *}
|
||||
<div class="customdevslider-swiper__slide-html" style="display:none;">
|
||||
{$s.text nofilter}
|
||||
</div>
|
||||
@@ -34,7 +33,6 @@
|
||||
{/foreach}
|
||||
</div>
|
||||
|
||||
{* ОДИН overlay content на весь слайдер *}
|
||||
<div class="customdevslider-swiper__content">
|
||||
<div class="customdevslider-swiper__text"></div>
|
||||
<div class="swiper-pagination customdevslider-swiper__pagination"></div>
|
||||
|
||||
Reference in New Issue
Block a user