I am trying to reuse my code: colorswap1, colorswap2 etc but for some reason my script is not doing so! please help
Code:<script type="text/javascript"> $(function() { var images = ['beige', 'green', 'red','whitebabysmall']; var max = images.length; var i = 1-36; // Get current image src var curSrc = $('#colorswap'[i]).attr('src'); // Find ID in image src var curID = curSrc.replace(/.*\/(.*?)\.gif/i, '$1'); var curIdx = 0; // Search image list for index of current ID while (curIdx < max) { if (images[curIdx] == curID) { break; } curIdx++; } // For convenience var imgSrcBase = '{{ STATIC_URL }}img/creighton/color/'; // Next image on button (and image) click $('#swapnextimg,#colorswap').click( function() { curIdx = (curIdx+1) % max; $("#colorswap").attr('src', imgSrcBase+images[curIdx]+'.gif'); }); // Prev image on button click $('#swapprevsimg').click( function() { curIdx = (curIdx+max-1) % max; $("#colorswap").attr('src', imgSrcBase+images[curIdx]+'.gif'); }); });



Reply With Quote


Bookmarks