gpt4 book ai didi

javascript - 将分页添加到我的轮播 (jQuery)

转载 作者:太空宇宙 更新时间:2023-11-04 15:27:35 25 4
gpt4 key购买 nike

我正在尝试向轮播添加一个简单的指示器。目前,指标的数量不必动态生成。我正在尝试在 BBC 上复制轮播主页。

BBC 网站上的指示器是右上角的橙色圆点。我不想让这些点成为相应幻灯片的链接,我只想让这些点根据您单击“上一个”或“下一个”来循环

例如:(o = 指标)

<prev      [IMGS]      next>
o o o

我的 jsFiddle:http://jsfiddle.net/yTKyU/

最佳答案

查看更新的 fiddle :http://jsfiddle.net/yTKyU/1/

$(document).ready(function() {

//rotation speed and timer
var speed = 5000;
var run = setInterval('rotate()', speed);

//calculate width dynamically for responsive design
var starting_width = $('#slides ul li').width($('#slides').outerWidth());

//grab the width and calculate left value
var item_width = $('#slides ul li').outerWidth();
var left_value = item_width * (-1);

//move the last item before first item, just in case user click prev button
$('#slides ul li:first').before($('#slides ul li:last'));

//set the default item to the correct position
$('#slides ul').css({
'left': left_value
});

//if user clicked on prev button
$('#prev').click(function() {

//get the right position
var left_indent = parseInt($('#slides ul').css('left')) + item_width;

//slide the item
$('#slides ul:not(:animated)').animate({
'left': left_indent
}, 200, function() {

//move the last item and put it as first item
$('#slides ul li:first').before($('#slides ul li:last'));

//set the default item to correct position
$('#slides ul').css({
'left': left_value
});

});
if ($('#pagination li span.current').parent().is(':first-child')) {
$('#pagination li span.current').removeClass('current');
$('#pagination li:last-child').children().addClass('current');
} else {
$('#pagination li span.current').parent().prev().children().addClass('current').addClass('new');
$('#pagination li span.current').removeClass('current');
$('#pagination li span.new').addClass('current').removeClass('new');
}
//cancel the link behavior
return false;

});


//if user clicked on next button
$('#next').click(function() {

//get the right position
var left_indent = parseInt($('#slides ul').css('left')) - item_width;

//slide the item
$('#slides ul:not(:animated)').animate({
'left': left_indent
}, 200, function() {

//move the first item and put it as last item
$('#slides ul li:last').after($('#slides ul li:first'));

//set the default item to correct position
$('#slides ul').css({
'left': left_value
});

});

//change the itemlist class
if ($('#pagination li span.current').parent().is(':last-child')) {
$('#pagination li span.current').removeClass('current');
$('#pagination li:first-child').children().addClass('current');
} else {
$('#pagination li span.current').parent().next().children().addClass('current').addClass('new');
$('#pagination li span.current').removeClass('current');
$('#pagination li span.new').addClass('current').removeClass('new');
}
//cancel the link behavior
return false;

});

//if mouse hover, pause the auto rotation, otherwise rotate it
$('#slides').hover(

function() {
clearInterval(run);
}, function() {
run = setInterval('rotate()', speed);
});

});

//function to click next link
//a timer will call this function, and the rotation will begin :)


function rotate() {
$('#next').click();
}​

关于javascript - 将分页添加到我的轮播 (jQuery),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13827062/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com