Add lightbox to img with variable sources
Hello,
I have a simple image swap function. You hove over thumbnails and a larger img is displayed in #main-img. However, how would I make it where when the #main-image is clicked, the variating src is selected and then linked to the actual image file.
Pseudo:
If
#main-img' clicked, THEN select current src and link to images/src.jpg
I hope that makes sense and thanks in advance to whoever can help!
- $(document).ready(function() {
- // Image swap on hover
- $(".imgBank ul li a img").hover(function(){
- $('#main-img').attr('src',$(this).attr('src').replace('images/large/', ''));
- });
- // Image preload
- var imgSwap = [];
- $(".imgBank ul li a img").each(function(){
- imgUrl = this.src.replace('large/', '');
- imgSwap.push(imgUrl);
- });
- $(imgSwap).preload();
- });
- $.fn.preload = function() {
- this.each(function(){
- $('<img/>')[0].src = this;
- });
- }