Jump to content

Need help with 3 image slideshow JavaScript


James92

Recommended Posts

a. Select one of the images to load automatically when the web page loads by modifying the HTML and placing a file name in the empty src property of the img tag with id="img2"b. Using JavaScript write the necessary functions to start the slideshow automatically and continuously cycle through the selected images displaying each one for 5 seconds.I don't know what I'm missing in my coding to make it work?Here's my entire websitehttp://jsfiddle.net/eqkhgxcL/

Link to comment
Share on other sites

Is this a Javascript assignment or a jQuery assignment? You probably shouldn't be mixing them both, especially if you're still learning.

 

You need to start with the basics. To begin with, do you know how to set the src property of an image element?

It's just one line of code. You can't move on until you're able to do that.

Link to comment
Share on other sites

It's a mix of both but for this certain part it has to be only JavaScript

 

Source Code

 

<img id="img2" src="batsignal.jpg">

 

JS Code

 

 

function preloadImages(){ var pictures = g.batmanImages.concat(g.batmanImages, g.signImages); var tempImage = new Image(); for (var i=0; i<pictures.length; i++){ tempImage.src = pictures; }}function slideShow(){ if (g.slideShow){ clearInterval(g.slideShow); g.slideShow = null; } else { g.slideShow = setInterval(changeSlide,5000); }}function changeSlide(){ g.slideCtr++; if (g.slideCtr > g.batmanImages.length-1){ g.slideCtr = 0; } img2.src = g.batmanImages[g.slideCtr]; g.img2 = document.getElementById("img2"); g.slideShow = 0; g.slideCtr = 0; g.x = null; g.y = null; g.objX = null; g.objY = null;}g.img2.onclick = slideShow;g.batmanImages = ["batsignal.jpg", "batmobile.jpg", "batmanflying.jpg"];

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...