javascript - My images won't show -
my images won't show when trying load page! trying make traffic light sequence (uk) shows colours when change lights button pressed!
<!doctype html> <html> <body> <h1><u><b>changing traffic lights</b></u><h1> <button type="button" onclick="changelights()"> change lights </button> <!-- creates button change lights --> <img id ="trafficlight" src="red.jpg"></img> <!-- creates first visible image on page , gives id can called later --> <script> var trafficlights = ["red-amber.jpg","green.jpg","amber.jpg","red.jpg"] //creates array lights var currentlight = 0 //creates counter variable function changelights () { //calls function , designs document.getelementbyid("trafficlight").src=trafficlights[currentlight] //calls image , enables changed currentlight=currentlight+1 //adds 1 counter if (currentlight>3){ currentlight=0 } } </script> </body> </html>
your code works. must have problem image source paths. because works correctly when change images remote lorempixel.
working jsfiddle here.
try fix image paths in js. luck.
var trafficlights = ["http://lorempixel.com/100/100","http://lorempixel.com/100/90","http://lorempixel.com/100/100","http://lorempixel.com/100/110"]
Comments
Post a Comment