【发布时间】:2016-06-29 16:03:43
【问题描述】:
我正在尝试自定义我的光滑滑块以匹配我的设计。现在我需要上一个和下一个按钮是滑块的实际上一个和下一个图像。
当您单击上一张图片时,您会向后滑动 1 张,当您单击下一张图片时,您会向前滑动 1 张。
这就是我的滑块在 html 中的样子
<div class="col-md-1 text-left">
<p class="left darkerfontcolor">prev</p>
</div>
<div class="col-md-10 text-center nopadding white-text">
<div class="slider">
<div class="slider-image" id="theslider1" style=
"background-image: url('img/bg/bg-1.jpg'); height: 600px; background-size: cover;
background-position: center center;">
<h3>Street life of Antwerp</h3>
<p class="largefontsize somemargin">Hello there!</p>
<div class="slider-buttons">
<a class="smallfontsize slider-button somemarginright"
href="#">More info</a> <a class=
"smallfontsize slider-button somemarginleft" href="#">Book
this tour</a>
</div>
</div>
<div class="slider-image" id="theslider2" style=
"background-image: url('img/bg/bg-2.jpg'); height: 600px; background-size: cover;
background-position: center center;">
<h3>Hey there, I have no text</h3>
<p class="largefontsize somemargin">Will you be my text?</p>
<div class="slider-buttons">
<a class="smallfontsize slider-button somemarginright"
href="#">More info</a> <a class=
"smallfontsize slider-button somemarginleft" href="#">Book
this tour</a>
</div>
</div>
<div class="slider-image" id="theslider3" style=
"background-image: url('img/bg/bg-3.jpg'); height: 600px; background-size: cover;
background-position: center center;">
<h3>Please...</h3>
<p class="largefontsize somemargin">It'll be fun!</p>
<div class="slider-buttons">
<a class="smallfontsize slider-button somemarginright"
href="#">More info</a> <a class=
"smallfontsize slider-button somemarginleft" href="#">Book
this tour</a>
</div>
</div>
</div>
</div>
<div class="col-md-1 text-right">
<p class="right darkerfontcolor">next</p>
</div>
所以目标是获取上一个和下一个图像作为上一个和下一个按钮。 我已经抓取了当前幻灯片的索引,并想从我的滑块容器中抓取下一张和上一张幻灯片的图像以注入 html,这就是我的做法
jQuery('.slider').on('afterChange', function(event, slick){
var activeSlide = jQuery('.slider').find('.slick-active');
var index = activeSlide.data('slick-index');
console.log(index);
});
问题是我不知道如何获取图像并将它们相应地注入到我的 html 中
【问题讨论】:
标签: javascript jquery html css