0

スライドショー用の次のスクリプトに問題があります。現在は静的で、スライドが回転するように 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>    

私はどんな答えにも非常に感謝します。

4

1 に答える 1

0

繰り返す関数内に遷移コードを記述します。

setinterval(function(){
//do something for every 2 seconds
},2000);

イベント間に遅延を導入したい場合

$(this).nextAll('a').bind(/*your code*/).delay( 800 );
于 2013-10-16T09:23:21.747 に答える