Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   Авто перекрутка (https://javascript.ru/forum/jquery/48401-avto-perekrutka.html)

sparklingman 02.07.2014 14:38

Авто перекрутка
 
Дорогие форумчане. Вот кусок кода. Нужно сделать, так чтоб каждую 2-5 сек. автоматически перекручивались блоки. В JS я не силен. Плиз помогите.

$(document).ready(function() {
    
    var $item = $('ul.list li'), //Cache your DOM selector
        visible = 1, //Set the number of items that will be visible
        index = 0, //Starting index
        endIndex = ( $item.length / visible ) - 3; //End index
    
    $('.news-blok .arrow-right').click(function(){
        if(index < endIndex ){
          index++;
          $item.animate({'left':'-=300px'});
        }
    });
    
    $('.news-blok .arrow-left').click(function(){
        if(index > 0){
          index--;            
          $item.animate({'left':'+=300px'});
        }
    });
    
});

sparklingman 02.07.2014 21:59

Нашел ответ, мне помог один отличный программист. Тему можете закрывать.
$(document).ready(function() {
    
    var item = $('ul.list li'), //Cache your DOM selector
        visible = 1, //Set the number of items that will be visible
        index = 0, //Starting index
        endIndex = ( $(item).length / visible ) - 3, //End index
        prokrutka = 2000; //Прокрутка каждые N мс.
    
    setInterval(function(){
        if(index < endIndex ){
          index++;
          $(item).animate({'left':'-=300px'});
        } else if(index == endIndex){
          index = 0;
          $(item).animate({'left':'0px'});
        }
    },2000);
    
    $('.arrow-right').click(function(){
        if(index < endIndex ){
          index++;
          $(item).animate({'left':'-=300px'});
        }
    });
    
    $('.arrow-left').click(function(){
        if(index > 0){
          index--;            
          $(item).animate({'left':'+=300px'});
        }
    });
    
});


Часовой пояс GMT +3, время: 18:00.