jquery - JavaScript code for my Image Gallery -
i making simple gallery page using html , css. coded onto html viewer , working fine when opened in google chrome , ie onmouseover not working. when go on selected thumbnail, supposed display larger image in bottom box not work.
i posted question before , got replies. ask if can please give me plain javascript code need put in make work. have code kindly gave works java script code if possible.
$(function(){ $('.thumbnails img').hover(function(){ $('#preview').attr('src',$(this).attr('src')); },null); });
thank all!
<!doctype html> <head> <title>gallery</title> <style type="text/css"> body { background: #222; margin-top: 100px; } h3 { color: #eee; font-family: verdana; } .thumbnails img { height: 100px; border: 4px solid #555; padding: 1px; margin: 0 10px 10px 0; } .thumbnails img:hover { border: 4px solid #00ccff; cursor:pointer; } .preview img { border: 4px solid #444; padding: 1px; width: 800px; } </style> </head> <body> <div class="gallery" align="center"> <div class="thumbnails"> <img onmouseover="preview.src=img1.src" id="img1" src="http://i60.tinypic.com/2qjj62b.jpg" alt="image not loaded"/> <img onmouseover="preview.src=img2.src" id="img2" src="http://i60.tinypic.com/mb4c21.jpg" alt="image not loaded"/> <img onmouseover="preview.src=img3.src" id="img3" src="http://i61.tinypic.com/35avvpw.jpg" alt="image not loaded"/> <img onmouseover="preview.src=img4.src" id="img4" src="http://i60.tinypic.com/29qnjme.jpg" alt="image not loaded"/> <img onmouseover="preview.src=img5.src" id="img5" src="http://i62.tinypic.com/zkmvd2.jpg" alt="image not loaded"/> <img onmouseover="preview.src=img6.src" id="img6" src="http://i61.tinypic.com/oqezus.jpg" alt="image not loaded"/> <img onmouseover="preview.src=img7.src" id="img7" src="http://i57.tinypic.com/1tx6oj.jpg" alt="image not loaded"/> <img onmouseover="preview.src=img8.src" id="img8" src="http://i58.tinypic.com/143onsj.jpg" alt="image not loaded"/> <img onmouseover="preview.src=img9.src" id="img9" src="http://i61.tinypic.com/2l16qf.jpg" alt="image not loaded"/> <img onmouseover="preview.src=img0.src" id="img0" src="http://i61.tinypic.com/21l0own.jpg" alt="image not loaded"/> </div></br> <div class="preview" align="center"> <img id="preview" src="http://i60.tinypic.com/2qjj62b.jpg" alt="no image loaded"/> </div> </br> </div> </body> </html>
here vanilla js version of gallery:
var images = document.getelementsbyclassname('thumbnails')[0].getelementsbytagname('img'); (var = 0; < images.length; i++) { images[i].onmouseover = function () { document.getelementbyid('preview').src = this.src; } }
see working here: http://jsfiddle.net/2am2n/5/
update
here's how use descriptions alt attributes:
document.getelementbyid('desc').innerhtml = this.alt; // goes inside our loop
here live example: http://jsfiddle.net/2am2n/6/
Comments
Post a Comment