Created
July 24, 2011 21:36
-
-
Save metaphox/1103135 to your computer and use it in GitHub Desktop.
cycleImages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| timers = []; | |
| var cycleImgs = function(imgs){ | |
| for(var j=0;j<timers.length;j++){clearTimeout(timers[j]);} | |
| var selector = '#bgimg'; | |
| var gonext = function(imgarray, idx){ | |
| //console.log(imgarray[idx]); | |
| var nextImage = new Image(); | |
| nextImage.onload = function(){ | |
| $(selector).stop().animate({opacity : 0 }, | |
| 250, | |
| function(){ | |
| $(selector).attr('src', imgarray[idx]); | |
| $(selector).animate({opacity : 1}, 250); | |
| if(++idx >= imgarray.length) idx = 0; | |
| }); | |
| timers.push(setTimeout(function(){gonext(imgarray, idx)}, 5000)); | |
| nextImage = nextImage.onload = nextImage.onabort = nextImage.onerror = null; | |
| } | |
| nextImage.src = imgarray[idx]; | |
| } | |
| gonext(imgs, 0); | |
| } | |
| frontImgs = $('#wrapper').attr('data-bgimg').split('|'); | |
| $('h2').click(function(){ | |
| $('.secondDirs').hide(); | |
| $(this).parent().children('.secondDirs').show(); | |
| cycleImgs(frontImgs); | |
| }); | |
| $('h3').click(function(){ | |
| $('.content').hide(); | |
| $(this).next().show(); | |
| var baseDir = 'content'; | |
| var secondDir = $(this).text(); | |
| var firstDir = $(this).parent().parent().children('h2').text(); | |
| var bgImgs = $(this).next().attr('data-bgimg').split('|'); | |
| var preloadimg = new Image(); | |
| for(var i=0;i<bgImgs.length;i++){preloadimg.src=bgImgs[i];} | |
| cycleImgs(bgImgs); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment