javascript - How to cycle through a series of images onClick -


i have page div holding grid of img elements. want each image, on click, cycle next image in series of three. repeat on each click until third image clicked , loops first image.

i have considered writing in javascript, struggling write method can without referencing specific filenames; easy if had 1 image wanted cycle 2 others because have conditional function called next image based on current one. can't write out each time 100+ images in grid on page. have long list of img elements , css defining divs right now, , i'm lost next step.

i'm eager suggest best language in , give me general sense of script doing , how interact img elements; don't expect write me!

css:

        .grid {             width: 980px;             height: auto;             margin-left: auto;             margin-right: auto;         }         img {             width: 200px;             padding-left: 20px;             padding-right: 20px;             padding-bottom: 20px;         } 

html:

     <div class="grid">          <img src="image1_first.jpg"></img> ...      </div> 

here's run trouble: need have 3 total images loaded (image1_first, image1_second, image1_third; image2_first, etc...)
displaying 1 per spot in "grid" until clicked.

the best language javascript, bit of jquery think. can cheating opacity made fade in: example, code won't work.

in html: img1 opacity = 1; img2 opacity = 0; img3 opacity = 0; in js: onclick {   if (img1opacity = 1){     img1opacity = 0;     img2opacity = 1;   } } 

ect.. slider can watch how other sliders made, it's not hard, put images side side , change left or margin of element. cool way slide in same side put images this: 1 2 3 1, when you're @ last one, can make left:0; or margin:0; go first 1 without rotating in otherside.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -