javascript - Prev and Next buttons switch images (links to images) in array??? -
these instructions:
"have image , 2 buttons, prev , next. have 10 images in array. when click on next, next picture should display , when click on prev, previous image should display."
this wrote far:
<html> <head> <title>image loop</title> </head> <body> <img src="http://placekitten.com/500/200" id="image" style="height:150px; width:150px" /> <input type="button" value="prev" name="previous_picture" onclick= nextimage();> <input type="button" value="next" name="next_picture"/> <script> function nextimage () { var = images.indexof(); var imagesrc = document.getelementbyid("image").src=images[i]; (i = weekdays.indexof(day); i<weekdays.length; i++) } function previmage () { } var images = new array( "http://placekitten.com/500/200", "http://placekitten.com/499/200", "http://placekitten.com/501/200", "http://placekitten.com/500/199" ); </script> </body> </html>
* image should loop around when gets end of array. don't know i'm doing... :( *
do more investigations, shows little effort.
i'll give pointers.
javascript: generic next item in array
javascript knows modulus operation: https://msdn.microsoft.com/nl-nl/library/9f59bza0(v=vs.94).aspx
prev = (index + length - 1 ) % length
next = (index + 1 ) % length
prev needs previmage() , next needs nextimage() functions
etc.
Comments
Post a Comment