Jquery 在幻灯片中设置间隔

Jquery 在幻灯片中设置间隔,jquery,setinterval,Jquery,Setinterval,我对以下用于幻灯片放映的脚本有问题。目前它是静态的,我的目标是包括setInterval,这样幻灯片就会旋转。有人能给我一些关于如何更好地实现这个方法的建议吗,因为我找不到设置setInterval的合适位置 代码如下: <script type="text/javascript"> $(document).ready(function() { var theImage = $('ul.photos li img'); var theWidth = theImage.widt

我对以下用于幻灯片放映的脚本有问题。目前它是静态的,我的目标是包括setInterval,这样幻灯片就会旋转。有人能给我一些关于如何更好地实现这个方法的建议吗,因为我找不到设置setInterval的合适位置

代码如下:

<script type="text/javascript">
$(document).ready(function() {
    var theImage = $('ul.photos li img');
var theWidth = theImage.width()
//wrap into mother div
$('ul.photos').wrap('<div id="mother" />');                 
//assign height width and overflow hidden to mother
$('#mother').css({
    width: function() {
    return theWidth;
  }, 
    height: function() {
    return theImage.height();
  }, 
    position: 'relative',
    overflow: 'hidden'      
});
    //get total of image sizes and set as width for ul 
var totalWidth = theImage.length * theWidth;
$('ul.photos').css({
    width: function(){
    return totalWidth;  
}               
});     

$(theImage).each(       
function(intIndex){             
$(this).nextAll('a')
.bind("click", function(){
    if($(this).is(".next")) {
        $(this).parent('li').parent('ul').animate({
            "margin-left": (-(intIndex + 1) * theWidth)             
                }, 1000)    
        } else if($(this).is(".previous")){
        $(this).parent('li').parent('ul').animate({
            "margin-left": (-(intIndex - 1) * theWidth)             
        }, 1000)    
        } else if($(this).is(".startover")){
        $(this).parent('li').parent('ul').animate({
            "margin-left": (0)              
        }, 1000)
}
});//close .bind()                                   
});//close .each()
});
</script>    

$(文档).ready(函数(){
var theImage=$('ul.photos li img');
var theWidth=theImage.width()
//裹在母亲的衣服里
$('ul.photos')。包装(“”);
//将“高度-宽度”和“溢出隐藏”指定给“母亲”
$(“#母亲”).css({
宽度:函数(){
返回宽度;
}, 
高度:函数(){
返回图像高度();
}, 
位置:'相对',
溢出:“隐藏”
});
//获取图像大小的总和并设置为ul的宽度
var totalWidth=图像长度*宽度;
$('ul.photos').css({
宽度:函数(){
返回总宽度;
}               
});     
$(图像)。每个(
函数(intIndex){
$(this.nextAll('a'))
.bind(“单击”,函数(){
if($(this).is(“.next”)){
$(this).parent('li').parent('ul').animate({
“左边距”:(-(索引内+1)*宽度)
}, 1000)    
}如果($(this).is(“.previous”)){
$(this).parent('li').parent('ul').animate({
“左边距”:(-(索引内-1)*宽度)
}, 1000)    
}如果($(this).is(“.startover”)){
$(this).parent('li').parent('ul').animate({
“左边距”:(0)
}, 1000)
}
});//close.bind()
});//关闭。每个()
});

我将非常感谢您的回答。

在函数中编写转换代码以重复

setinterval(function(){
//do something for every 2 seconds
},2000);
如果你想在事件之间引入延迟

$(this).nextAll('a').bind(/*your code*/).delay( 800 );

你好谢谢你的回答。我不确定该命名什么函数,因为如果不定义函数,整个脚本将停止工作。我对JavaScript和jQuery不是很精通,所以我可能把事情搞砸了。但是,您希望生成的代码是什么样子的?