html - How can I make an image carousel using HTML5, CSS and Javascript? -
when run file, can see first image doesn't change after slideinterval time.
i think problem in javascript code because html , css part of project supposed do, done. however, image doesn't change.
i bit of noob javascript please point out if obvious. beforehand!!
this code:
first javascript, css , html:
var slideinterval = 3500; function getfigures() { return document.getelementbyid("carousel").getelementsbytagname("figure"); } function nextimage() { var pointer; //var figures = getfigures; var figures = getfigures(); for(var = 0; < figures.length; i++){ if(figures[i].classname == "visible") figures[i].classname = ""; pointer = i; } if (++pointer == figures.length) { pointer = 0; } figures[pointer].classname = 'visible'; settimeout(nextimage(), slideinterval); } function startplayback() { settimeout(nextimage(), slideinterval); } startplayback(); section#carousel > figure > img { display: none; margin: 0px auto; } section#carousel > figure.visible > img { display: block; position: relative; overflow: hidden; } section#carousel > figure > figcaption { display: none; } section#carousel > figure.visible > figcaption { display: block; text-align: center; font-weight: bold; font-size: 1.5em; } <!doctype html> <html lang="en-us"> <head> <title>contoso news</title> <link rel="stylesheet" href="../styles/style.css" /> </head> <body> <section id="carousel"> <figure class="visible"> <img src="../media/efficient_cars.png" alt="efficient cars"> <figcaption>efficient cars used in future</figcaption> </figure> <figure> <img src="../media/natural_disasters.png" alt="natural disasters"> <figcaption>many natural disasters thought happen more often</figcaption> </figure> <figure> <img src="../media/health_records.png" alt="health records"> <figcaption>many doctors moving digital health records year</figcaption> </figure> </section> <script type="text/javascript" src="../js/carousel_script.js"></script> </body> </html>
use can use jssor slider plugin create responsively carousels. refer https://www.jssor.com/
Comments
Post a Comment