如何自动播放此javascript滑块?
我找到了这个漂亮的js滑块,它通过单击单选按钮,选择要查看的幻灯片来工作 我希望它能自动播放幻灯片,并给它一段时间播放幻灯片和过渡,但我真的不知道该把这些值放在哪里 我已经看到了关于类似问题的其他问题,但找不到我问题的正确答案。请帮忙如何自动播放此javascript滑块?,javascript,jquery,slider,autoplay,Javascript,Jquery,Slider,Autoplay,我找到了这个漂亮的js滑块,它通过单击单选按钮,选择要查看的幻灯片来工作 我希望它能自动播放幻灯片,并给它一段时间播放幻灯片和过渡,但我真的不知道该把这些值放在哪里 我已经看到了关于类似问题的其他问题,但找不到我问题的正确答案。请帮忙 <script type="text/javascript"> $(document).ready(function () { var showCaseItems = $('.show-case-item').hide();
<script type="text/javascript">
$(document).ready(function () {
var showCaseItems = $('.show-case-item').hide();
var splashes = $('.splash').hide();
//get each image for each slide and set it as a background of the slide
// splashes.each(function () {
// var img = $(this).find('img');
// var imgSrc = img.attr('src');
// img.css('visibility', 'hidden');
// $(this).css({ 'background-image': 'url(' + imgSrc + ')', 'background-repeat': 'no-repeat' });
// });
splashes.eq(0).show();
showCaseItems.eq(0).show();
var prevIndex = -1;
var nextIndex = 0;
var currentIndex = 0;
$('#banner-pagination li a').click(function () {
nextIndex = parseInt($(this).attr('rel'));
if (nextIndex != currentIndex) {
$('#banner-pagination li a').html('<img src="assets/img/slidedot.png" alt="slide"/>');
$(this).html('<img src="assets/img/slidedot-active.png" alt="slide"/>');
currentIndex = nextIndex;
if (prevIndex < 0) prevIndex = 0;
splashes.eq(prevIndex).css({ opacity: 1 }).animate({ opacity: 0 }, 500, function () {
$(this).hide();
});
splashes.eq(nextIndex).show().css({ opacity: 0 }).animate({ opacity: 1 }, 500, function () { });
showCaseItems.eq(prevIndex).css({ opacity: 1 }).animate({ opacity: 0 }, 500, function () {
$(this).hide();
showCaseItems.eq(nextIndex).show().css({ opacity: 0 }).animate({ opacity: 1 }, 200, function () { });
});
prevIndex = nextIndex;
}
return false;
});
});
</script>
$(文档).ready(函数(){
var showCaseItems=$('.show-case-item').hide();
var splash=$('.splash').hide();
//获取每张幻灯片的每张图像,并将其设置为幻灯片的背景
//飞溅。每个(功能(){
//var img=$(this.find('img');
//var imgSrc=img.attr('src');
//css(‘可见性’、‘隐藏’);
//$(this.css({'background image':'url('+imgSrc+'),'background repeat':'no repeat'});
// });
splashes.eq(0.show();
showCaseItems.eq(0.show();
var指数=-1;
var-nextIndex=0;
var currentIndex=0;
$(“#标题分页li a”)。单击(函数(){
nextIndex=parseInt($(this.attr('rel'));
如果(nextIndex!=当前索引){
$('#banner pagination li a').html('';
$(this.html(“”);
currentIndex=nextIndex;
如果(prevIndex<0)prevIndex=0;
eq(prevIndex).css({opacity:1}).动画({opacity:0},500,函数(){
$(this.hide();
});
splashes.eq(nextIndex).show().css({opacity:0}).animate({opacity:1},500,function(){});
showCaseItems.eq(prevIndex).css({opacity:1}).动画({opacity:0},500,函数(){
$(this.hide();
showCaseItems.eq(nextIndex).show().css({opacity:0}).animate({opacity:1},200,function(){});
});
prevIndex=nextIndex;
}
返回false;
});
});
您可以使用jquery和setTimeout
setTimeout(function() {$('#banner-pagination li a').trigger('click');}, 1500);
此代码将每1.5秒循环一次,并触发单击
#banner pagination li a
您可以使用jquery触发器事件并强制单击单选按钮单击事件
$('foo')。触发器('click')
谢谢您好,非常感谢您的回答,它只起到部分作用:我有三张幻灯片,您建议的代码使它从第一张幻灯片滑到第三张幻灯片,然后什么也没有。我想玩一下,但如果你知道为什么会发生这种情况,请告诉我!我实际上有几十个.css和.js。我担心摆弄它会占用我更多的办公时间!我试图将“var nextIndex”设置为1,但没有结果。嗯。
setInterval(function()
{$('#banner-pagination li a[rel='+((currentIndex+1)%3)+']').trigger('click');},5000);