简体   繁体   English

jQuery图像滑块,可滑动

[英]jQuery image slider with jump to slide

I am trying to create a content slider same as here the only thing is that they have text and images and i want only images. 我正在尝试创建与此处相同的内容滑块,唯一的是它们具有文本和图像,而我只需要图像。

Basically on first page it shows thumbnails so when you click any of them it jumps to that particular slide. 基本上在第一页上会显示缩略图,因此当您单击任何缩略图时,它会跳至该特定幻灯片。

I have tried and setup the slider with swiper jquery plugin but i couldn't make it to jump to specific slide here is my code: 我已经尝试并使用swiper jquery插件设置了滑块,但是我无法使其跳转到特定的幻灯片,这是我的代码:

    <div class="swiper-container">
    <div class="swiper-wrapper">
    <div class="swiper-slide" style="background-image:url(http://lorempixel.com/1000/1000/nightlife/5)">
        <div class="block">
            <a href="#page6">Jumo to page 1</a>
        </div>
        <div class="block">
            <a href="#page2">Jumo to page 2</a>
        </div>
        <div class="block">
            <a href="#page3">Jumo to page 3</a>
        </div>
    </div>
    <div id="page2" data-page-number="2"  class="swiper-slide" style="background-image:url(http://lorempixel.com/1000/1000/nightlife/1)"></div>
    <div id="page3" data-page-number="3"  class="swiper-slide" style="background-image:url(http://lorempixel.com/1000/1000/nightlife/2)"></div>
    <div id="page4" data-page-number="4"  class="swiper-slide" style="background-image:url(http://lorempixel.com/1000/1000/nightlife/3)"></div>
    <div id="page5" data-page-number="5" class="swiper-slide" style="background-image:url(http://lorempixel.com/1000/1000/nightlife/4)"></div>
    <div id="page6" data-page-number="6" class="swiper-slide"><h1>THIS IS PAGE 6</h1></div>
    </div>

    <div class="swiper-pagination swiper-pagination-white"></div>

    <div class="swiper-button-next swiper-button-white"></div>
    <div class="swiper-button-prev swiper-button-white"></div>
</div>

<script>
var swiper = new Swiper('.swiper-container', {
    pagination: '.swiper-pagination',
    paginationClickable: '.swiper-pagination',
    nextButton: '.swiper-button-next',
    prevButton: '.swiper-button-prev',
    spaceBetween: 30,
    effect: 'fade'
});
</script>

Jsfiddle here https://jsfiddle.net/yuv72u60/ Jsfiddle在这里https://jsfiddle.net/yuv72u60/

Seeking help! 寻求帮助!

Thank you 谢谢

HTML HTML

            <div class="block">
                <a href="1">Jumo to page 1</a>
            </div>
            <div class="block">
                <a href="2">Jumo to page 2</a>
            </div>
            <div class="block">
                <a href="3">Jumo to page 3</a>
            </div>

JS JS

$(".block a").click(function(){

   var index=$(this).attr('href');
    swiper.slideTo(index);
});

The above mentioned are changes in have made to your JS fiddle in the HTML and JS section. 上面提到的是对HTMLJS部分中的JS小提琴所做的更改。 index in the above js is the position of your page. 上面的js中的index是页面的位置。

DEMO DEMO

There is an API in Slider itself for your requirement I have updated your Fiddle slightly for that API to work Slider本身有一个API可以满足您的要求,我已经对Fiddle进行了小幅更新,以便该API可以正常工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM