Backstretch jQuery点导航

时间:2016-11-16 14:49:21

标签: jquery jquery-plugins slider jquery-backstretch

我正在尝试使用点来为后伸滑块构建导航。

目前我正在使用点的值更改为幻灯片,并在点击时显示该值。

让它自动播放1或2张幻灯片并点击第一个点,索引返回01而不是0.这会打破自动播放滑块以及导航。

谷歌搜索后,我似乎找不到任何修改,任何想法?

$(document).ready(function(){
	$(".slider").backstretch([
	"http://lw.dev.plx.mk/wp-content/uploads/2016/10/iStock_000015135168Large.jpg",
	"http://lw.dev.plx.mk/wp-content/uploads/2016/10/IMG_2961.jpg",
	"http://lw.dev.plx.mk/wp-content/uploads/2016/10/Global-Legend-White-conservatory-1-bespoke-external.jpg",
	"http://lw.dev.plx.mk/wp-content/uploads/2016/10/Buckley-3.jpg",		],{
		duration:3000,
		fade:750,
	});
	$('#dot-0').addClass('selected');

	$('.dot').click(function() {
	    $('.slider').backstretch("show", ($(this).attr('value')));
	    console.log('Value - ' + ($(this).attr('value')));
	    $('.dot').removeClass('selected');
	    $(this).addClass('selected');
	});

	$('.slider').on("backstretch.before", function (e, instance, index) {
		console.log('Index - ' + index);
		var currentSlide = $('#dot-' + index);
		$('.dot').removeClass('selected');
		$(currentSlide).addClass('selected');
	});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-backstretch/2.0.4/jquery.backstretch.min.js"></script>
<div class="slider" style="position: relative; z-index: 0; background: none;">
		<div class="slider-dots">
			<div class="dot" id="dot-0" value="0">x</div>
			<div class="dot" id="dot-1" value="1">x</div>
			<div class="dot" id="dot-2" value="2">x</div>
			<div class="dot" id="dot-3" value="3">x</div>
		</div>
</div>

1 个答案:

答案 0 :(得分:0)

	$('.dot').first().addClass('selected');
	
	var instance = $(".slider").data("backstretch");
	$('.dot').click(function () {
	  var index = $('.dot').index( $(this) );
	  $('.dot').removeClass('selected');
	  $(this).addClass('selected');
	  instance.show(index);
	  return false;
	});
	
	$('.slider').on("backstretch.before", function (e, instance, index) {
		var currentSlide = $('#dot-' + index);
		$('.dot').removeClass('selected');
		$(currentSlide).addClass('selected');
	});

使用上面的代码修复