0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

自作スライダーにページネーションをつけたいのですが・・

Posted at

自作でスライダーを作り、ページネーションを追加したいのですが、どうもうまくいかず。。。
下記のコードにどう追加したらいいのか教えてくださいT_T

スライダー部分は下記になります。

//slider
var slideWidth = $('.slide').outerWidth(),
slideHeight = $('.slide').height(),
slideNum = $('.slide').length,
slideSetWidth = slideWidth * slideNum;
$('.slideSet').css('width', slideSetWidth);	
$('.slider').css('height', slideHeight);

$(window).on('load resize', function(){
	slideWidth = $('.slide').outerWidth(),
	slideHeight = $('.slide').height(),
	slideNum = $('.slide').length,
	slideSetWidth = slideWidth * slideNum;
	$('.slideSet').css('width', slideSetWidth);	
	$('.slider').css('height', slideHeight);
});
var size = 0;
var xwidth = $('div.slider').width();
var slideCurrent = 0;	

var sliding = function(){
	if( slideCurrent < 0 ){
		slideCurrent = slideNum - 1;

	}else if( slideCurrent > slideNum - 1 ){
		slideCurrent = 0;
	}
	$('.slide_nav').find('li a').removeClass('active');
	$('.slide_nav li a').eq(slideNum).addClass('flex-active');

	$('.slideSet').stop().animate({
		left: slideCurrent * -100 +'vw'
	});
}
setInterval(function(){
	slideCurrent++;
	sliding();
},8000);

$('.slider_prev').click(function(){
	slideCurrent--;
	sliding();
});

$('.slider_next').click(function(){
	slideCurrent++;
	sliding();
});

ページネーション自動追加は下記です。

// ページネーション追加
var html = '

1';
for (var i=2; i<=slideNum; i++) {
html += ''+slideNum+'';
};
$('.slide_nav').append(html);

よろしくお願いいたします!

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?