使用方法
- //current position
- var pos = 0;
- //number of slides
- var totalSlides = $('#slider-wrap ul li').length;
- //get the slide width
- var sliderWidth = $('#slider-wrap').width();
-
- $(document).ready(function(){
-
- /*****************
- BUILD THE SLIDER
- *****************/
- //set width to be 'x' times the number of slides
- $('#slider-wrap ul#slider').width(sliderWidth*totalSlides);
-
- //next slide
- $('#next').click(function(){
- slideRight();
- });
-
- //previous slide
- $('#previous').click(function(){
- slideLeft();
- });
-
-
-
- /*************************
- //*> OPTIONAL SETTINGS
- ************************/
- //automatic slider
- var autoSlider = setInterval(slideRight, 3000);
-
- //for each slide
- $.each($('#slider-wrap ul li'), function() {
- //set its color
- var c = $(this).attr("data-color");
- $(this).css("background",c);
-
- //create a pagination
- var li = document.createElement('li');
- $('#pagination-wrap ul').append(li);
- });
-
- //counter
- countSlides();
-
- //pagination
- pagination();
-
- //hide/show controls/btns when hover
- //pause automatic slide when hover
- $('#slider-wrap').hover(
- function(){ $(this).addClass('active'); clearInterval(autoSlider); },
- function(){ $(this).removeClass('active'); autoSlider = setInterval(slideRight, 3000); }
- );
-
-
-
- });//DOCUMENT READY
-
-
-
- /***********
- SLIDE LEFT
- ************/
- function slideLeft(){
- pos--;
- if(pos==-1){ pos = totalSlides-1; }
- $('#slider-wrap ul#slider').css('left', -(sliderWidth*pos));
-
- //*> optional
- countSlides();
- pagination();
- }
-
-
- /************
- SLIDE RIGHT
- *************/
- function slideRight(){
- pos++;
- if(pos==totalSlides){ pos = 0; }
- $('#slider-wrap ul#slider').css('left', -(sliderWidth*pos));
-
- //*> optional
- countSlides();
- pagination();
- }
-
-
-
-
- /************************
- //*> OPTIONAL SETTINGS
- ************************/
- function countSlides(){
- $('#counter').html(pos+1 + ' / ' + totalSlides);
- }
-
- function pagination(){
- $('#pagination-wrap ul li').removeClass('active');
- $('#pagination-wrap ul li:eq('+pos+')').addClass('active');
- }
//current position
var pos = 0;
//number of slides
var totalSlides = $('#slider-wrap ul li').length;
//get the slide width
var sliderWidth = $('#slider-wrap').width();
$(document).ready(function(){
/*****************
BUILD THE SLIDER
*****************/
//set width to be 'x' times the number of slides
$('#slider-wrap ul#slider').width(sliderWidth*totalSlides);
//next slide
$('#next').click(function(){
slideRight();
});
//previous slide
$('#previous').click(function(){
slideLeft();
});
/*************************
//*> OPTIONAL SETTINGS
************************/
//automatic slider
var autoSlider = setInterval(slideRight, 3000);
//for each slide
$.each($('#slider-wrap ul li'), function() {
//set its color
var c = $(this).attr("data-color");
$(this).css("background",c);
//create a pagination
var li = document.createElement('li');
$('#pagination-wrap ul').append(li);
});
//counter
countSlides();
//pagination
pagination();
//hide/show controls/btns when hover
//pause automatic slide when hover
$('#slider-wrap').hover(
function(){ $(this).addClass('active'); clearInterval(autoSlider); },
function(){ $(this).removeClass('active'); autoSlider = setInterval(slideRight, 3000); }
);
});//DOCUMENT READY
/***********
SLIDE LEFT
************/
function slideLeft(){
pos--;
if(pos==-1){ pos = totalSlides-1; }
$('#slider-wrap ul#slider').css('left', -(sliderWidth*pos));
//*> optional
countSlides();
pagination();
}
/************
SLIDE RIGHT
*************/
function slideRight(){
pos++;
if(pos==totalSlides){ pos = 0; }
$('#slider-wrap ul#slider').css('left', -(sliderWidth*pos));
//*> optional
countSlides();
pagination();
}
/************************
//*> OPTIONAL SETTINGS
************************/
function countSlides(){
$('#counter').html(pos+1 + ' / ' + totalSlides);
}
function pagination(){
$('#pagination-wrap ul li').removeClass('active');
$('#pagination-wrap ul li:eq('+pos+')').addClass('active');
}
站长提示:
1. 苦力吧素材官方QQ群:
950875342
2. 平台上所有素材资源,需注册登录会员方能正常下载。
3. 会员用户积极反馈网站、素材资源BUG或错误问题,每次奖励
2K币。
4. PHP源码类素材,如需协助安装调试,或你有二次开发需求,可联系苦力吧客服。
5. 付费素材资源,需充值后方能下载,如有任何疑问可直接联系苦力吧客服