gpt4 book ai didi

javascript - 带有缩略图的中心幻灯片无法正常工作 iDangero.us 的 Swiper

转载 作者:太空宇宙 更新时间:2023-11-04 10:36:14 26 4
gpt4 key购买 nike

我正在使用 iDangero.us 插件的 Swiper。我创建的布局包含 6 个 slider 图像和 6 个缩略图。

如果我让缩略图居中对齐,插件会以某种方式搞砸。为此,我将 centeredSlides var 更改为 false

这是一个 JSFiddle:https://jsfiddle.net/fa4218de/5/

有人可以帮我解决这个问题吗?或者如果有任何解决方法..

Swipper API Docs

最佳答案

万一有人需要回答这个问题。我创建了自己的解决方案,方法是将缩略图链接到单个滑动器并根据缩略图的子编号旋转它们。下面是代码。

JS

jQuery(document).ready(function($) {

var galleryTop = new Swiper('.gallery-top', {
paginationClickable: true,
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',
spaceBetween: 30,

});

// Make first child of div active
$(".portfolios-thumb-wrapper .container .row div:first-child").addClass("active");


// When click on any of the thumbnails with classname 'slide_no' it
// gets the child number of the div and then I just use that number
// to rotate to that specific slide number by 'slideTo' callback
$('.slide_no').each(function (i) {
$(this).click(function (e) {
e.preventDefault();
var thumb = i;
galleryTop.slideTo( thumb,1000,false );
$('.slide_no').removeClass('active');
$(this).addClass('active');

});
});
});

PHP 和 HTML (WordPress),以防您需要了解标记

<div class="portfolios-wrapper">
<?php if ( $postslist->have_posts() ) : ?>
<div class="swiper-container gallery-top">
<div class="swiper-wrapper gallery_top_slides">

<?php while ( $postslist->have_posts() ) : $postslist->the_post(); ?>

<?php
$post_id = $post->ID;
$permalink = get_post_permalink( $post_id );
$backgroundImage = get_post_meta( $post_id, 'portfolio_background_image', true );

?>

<div class="swiper-slide top_slide_<?php echo $top_counter;?>" style="background-image: url('<?php echo $backgroundImage; ?>');">

<div class="portfolio-details" style="background-color:transparent">
<div class="container" style="background-color:transparent">
<div class="row">
<div class="col-md-6">
<div class="portfololio-thumb">
<?php echo the_post_thumbnail( 'large' );?>
<?php echo the_title( '<h2>', '</h2>', true );?>
</div>
</div>

<div class="col-md-6">

<div class="portfololio-excerpt">
<?php echo the_title( '<h2>', '</h2>', true );?>
<p><?php echo get_the_date( 'M Y' ); ?></p>
<span class="excerpt"><?php echo the_excerpt(); ?></span>
</div>
</div>

</div>
</div>
</div>
</div>

<?php $top_counter++; endwhile; ?>
</div>
<div class="container custom_adjust">
<div class="swiper-button-next custom-btn-next">Next</div>
<div class="swiper-button-prev custom-btn-prev">Previous</div>
</div>
</div>
<?php endif; ?>
</div>

<div class="portfolios-thumb-wrapper">
<?php if ( $postslist->have_posts() ) : ?>
<div class="container">
<div class="row">

<?php while ( $postslist->have_posts() ) : $postslist->the_post(); ?>

<?php if (has_post_thumbnail( $post->ID ) ): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
<?php endif; ?>

<div class="col-md-2 slide_no">
<div class="thumb_slide" style="background-image: url(' <?php echo $image[0]; ?> ')">
</div>
<div class="portfolio-title"><?php echo the_title( '<h2>', '</h2>', true );?> </div>
</div>

<?php $thumb_counter++; endwhile; ?>
</div>
</div>

<?php endif; ?>
</div>

关于javascript - 带有缩略图的中心幻灯片无法正常工作 iDangero.us 的 Swiper,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36120639/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com