Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
268 views
in Technique[技术] by (71.8m points)

javascript - JavaScript滑块不起作用(Javascript slider not works)

var slideIndex = 0; 
showSlides();
function showSlides() 
{ 
    var i; 
    var slides = document.getElementsByClassName("image-sliderfade");  
    var dots = document.getElementsByClassName("dot");  
    for (i = 0; i < slides.length; i++) { 
        // initially set the display to  
        // none for every image. 
        slides[i].style.display = "none";  
    } 
    slideIndex++;  
    if (slideIndex > slides.length)  
    { 
        slideIndex = 1; 
    } 
    for (i = 0; i < dots.length; i++) { 
        dots[i].className = dots[i].className. 
                            replace(" active", ""); 
    } 
    slides[slideIndex - 1].style.display = "block"; 
    dots[slideIndex - 1].className += " active"; 
    setTimeout(showSlides, 2000);  
} 

i try this for auto slider but it gives this error: Uncaught SyntaxError: Unexpected token '(' or it tells that showSlides() is undefined(我为自动滑块尝试了此操作,但它给出了以下错误:未捕获的SyntaxError:意外的标记'('或它表明showSlides()未定义)

  ask by sinandede translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Please call function after define it.(定义后请调用函数。)

var slideIndex = 0; 

function showSlides() 
{ 
    var i; 
    var slides = document.getElementsByClassName("image-sliderfade");  
    var dots = document.getElementsByClassName("dot");  
    for (i = 0; i < slides.length; i++) { 
        // initially set the display to  
        // none for every image. 
        slides[i].style.display = "none";  
    } 
    slideIndex++;  
    if (slideIndex > slides.length)  
    { 
        slideIndex = 1; 
    } 
    for (i = 0; i < dots.length; i++) { 
        dots[i].className = dots[i].className. 
                            replace(" active", ""); 
    } 
    slides[slideIndex - 1].style.display = "block"; 
    dots[slideIndex - 1].className += " active"; 
    setTimeout(showSlides, 2000);  
};
showSlides();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...