Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Ustalenie intervalu
Forum PHP.pl > Forum > Po stronie przeglądarki > JavaScript
kiepski96
Witam,

Stworzyłem slider, który pokazuje po kolei divy co jakiś czas. Jest za to odpowiedziany dany interwał, który ustalę.
Lecz niestety interwał również jest zanim się pokaże pierwszy div, trzea czekać na niego 4 sekundy.

Jak przerobić kod, aby po wejściu na stronę slider od razu pokazał diva bez interwału ?

Kod
var intervalId;
$(function(){
  
  
    function cycleImage(){
        
        var onLastLi = $("#thumbs li:last").hasClass("current");
        console.log(onLastLi);
        
        var currentImage = $("#thumbs li.current").html();
        var targetImage = $('div.feature-photo');
        console.info(currentImage);
        console.info(targetImage);        
        $(targetImage).hide().html(currentImage).fadeIn();
        
        var currentLi = $("#thumbs li.current");
        currentLi.removeClass("current");
        
        if(onLastLi){
            $("#thumbs li:first").addClass("current");
        }
        
        currentLi.next().addClass("current");
                
    };
    
   intervalID = setInterval(cycleImage, 4000);
    
    
    
});
trueblue
  1. $(function(){
  2.  
  3.  
  4. function cycleImage(){
  5.  
  6. var onLastLi = $("#thumbs li:last").hasClass("current");
  7. console.log(onLastLi);
  8.  
  9. var currentImage = $("#thumbs li.current").html();
  10. var targetImage = $('div.feature-photo');
  11. console.info(currentImage);
  12. console.info(targetImage);
  13. $(targetImage).hide().html(currentImage).fadeIn();
  14.  
  15. var currentLi = $("#thumbs li.current");
  16. currentLi.removeClass("current");
  17.  
  18. if(onLastLi){
  19. $("#thumbs li:first").addClass("current");
  20. }
  21.  
  22. currentLi.next().addClass("current");
  23. setTimeout(cycleImage, 4000);
  24.  
  25. };
  26.  
  27. cycleImage();
  28.  
  29.  
  30.  
  31. });
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.