JavaScript - Please Help - Urgent -fading Rotating Images
Hi
I usually work in html, but I am trying to put up rotating images that fade. I found some Javascript coding but it isn't working correctly. I only see the first image and it fades but nothing happens after that. This is the code I have: Code: <script language="JavaScript"> <!-- Begin var slideShowSpeed = 5000; var crossFadeDuration = 3; var Pic = new Array(); Pic[0] = 'image1.jpg' Pic[1] = 'image2.jpg' Pic[2] = 'image3.jpg' Pic[3] = 'image1.jpg' Pic[4] = 'image2.jpg' // do not edit anything below this line var t; var j = 0; var p = Pic.length; var preLoad = new Array(); for (i = 0; i < p; i++) { preLoad[i] = new Image(); preLoad[i].src = Pic[i]; } function runSlideShow() { if (document.all) { document.images.SlideShow.style.filter="blendTrans(duration=2)"; document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)"; document.images.SlideShow.filters.blendTrans.Apply(); } document.images.SlideShow.src = preLoad[j].src; if (document.all) { document.images.SlideShow.filters.blendTrans.Play(); } j = j + 1; if (j > (p - 1)) j = 0; t = setTimeout('runSlideShow()', slideShowSpeed); } // End --> </script> <body link="Red" vlink="Red" alink="Red" leftmargin=0 topmargin=0 bgcolor="Black"onLoad="runSlideShow()"> <img src="images/image1.jpg" alt="" name="SlideShow" id="SlideShow" width="300" height="200" border="0" align="left"> Can some assist me twith this? Thanks, Lisa Similar TutorialsHey Guys, I'm pretty new to Javascript, maybe you can help me with a small piece. I have 4 images, they are displayed 2x2. Initially they rest at 0.3 opacity.When you hover over one, it goes to 1 opacity. When you click an image, it becomes the selected image and stays at 1 opacity. I have this all working fine. My problem is, when you click another image, the "selected" image stays at 1 opacity until you roll over it again. I want it to automatically fade back to 0.3 opacity when another image is selected. I will attach my code: Code: <style type="text/css"> .MouseOver { opacity:0.3; filter:alpha(opacity=30); } </style> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"> </script> <script type="text/javascript"> currentImage=null; $(function() { $('.MouseOver').each(function() { $(this).hover( function() { $(this).stop().animate({ opacity: 1.0 }, 300); }, function() { if(currentImage != this) { $(this).stop().animate({ opacity: 0.3 }, 300); } }) }); }); function doSomething(pic) { currentImage=pic; } </script> The images then have .MouseOver class and the onClick calls the doSomething function. I'd appreciate any help you can give me. Thanks so much. I've prepared the following page: http://www.ko-go.gr/restaurant/index1a.html but I would prefer the background images to fade in and out rather than change abruptly. I've spent hours searching for appropriate code, but have met a dead end so far. Incidentally, I presume that the delay before the first background image appears is because of all the images pre-loading. Can anyone suggest a way to immediately display the first image? Thanks for taking the time to read this... Alrighty so here's what I have. Live example: http://www.thestrikeforum.com/ex/ It's a image slideshow that dynamically gets all the images (via php) in the current directory and puts them into the slideshow array. The array then randomly displays the images in the slideshow (via javascript). There are 5 images in the folder rotateimage which also has the php script getimages.php in it. Currently only the first image fades in however I want all the images to fade in as the first one does. Codes: Php script that gets all the images for the array: PHP Code: <? //PHP SCRIPT: getimages.php Header("content-type: application/x-javascript"); //This function gets the file names of all images in the current directory //and ouputs them as a JavaScript array function returnimages($dirname=".") { $pattern="(\.jpg$)|(\.png$)|(\.jpeg$)|(\.gif$)"; //valid image extensions $files = array(); $curimage=0; if($handle = opendir($dirname)) { while(false !== ($file = readdir($handle))){ if(eregi($pattern, $file)){ //if this file is a valid image //Output it as a JavaScript array element echo 'galleryarray['.$curimage.']="'.$file .'";'; $curimage++; } } closedir($handle); } return($files); } echo 'var galleryarray=new Array();'; //Define array in JavaScript returnimages() //Output the array elements containing the image file names ?> Main html page with the javascript: Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script src="rotateimage/getimages.php"></script> <script type="text/javascript"> var curimg=0 var max=galleryarray.length var random=Math.floor(Math.random()*max) function rotateimages(){ document.getElementById("slideshow").setAttribute("src", "rotateimage/"+galleryarray[random]) //curimg=(curimg<galleryarray.length-1)? curimg+1 : 0 random=Math.floor(Math.random()*max) } function initImage() { imageId = 'slideshow'; image = document.getElementById(imageId); setOpacity(image, 0); image.style.visibility = 'visible'; fadeIn(imageId,0); } function setOpacity(obj, opacity) { opacity = (opacity == 100)?99.999:opacity; // IE/Win obj.style.filter = "alpha(opacity:"+opacity+")"; // Safari<1.2, Konqueror obj.style.KHTMLOpacity = opacity/100; // Older Mozilla and Firefox obj.style.MozOpacity = opacity/100; // Safari 1.2, newer Firefox and Mozilla, CSS3 obj.style.opacity = opacity/100; } function fadeIn(objId,opacity) { if (document.getElementById) { obj = document.getElementById(objId); if (opacity <= 100) { setOpacity(obj, opacity); opacity += 10; window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100); } } } window.onload=function(){ setInterval("rotateimages()", 2500) initImage() } </script> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Test</title> </head> <body> <img src="rotateimage/pic1.jpg" name="slideshow" width="350" height="350" id="slideshow"/> </body> </html> If anyone could assist me in doing so or can help me find a better way to do the fading images for the slideshow feel free to share.. here's the main page code WITHOUT the fading code: Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script src="rotateimage/getimages.php"></script> <script type="text/javascript"> var curimg=0 var max=galleryarray.length var random=Math.floor(Math.random()*max) function rotateimages(){ document.getElementById("slideshow").setAttribute("src", "rotateimage/"+galleryarray[random]) //curimg=(curimg<galleryarray.length-1)? curimg+1 : 0 random=Math.floor(Math.random()*max) } window.onload=function(){ setInterval("rotateimages()", 2500) initImage() } </script> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Test</title> </head> <body> <img src="rotateimage/pic1.jpg" name="slideshow" width="350" height="350" id="slideshow"/> </body> </html> I'm designing a page to fade multiple images (three) in and out over a set period of time (one minute, say). The code I have works as follows: I define an array and fill it with the div objects I want to fade in and out. I have some simple tags (2 for opaque, 1 for fading in, -1 for fading out, etc.) that I set to show the state of the object. First I check if the object is opaque, and if so set it to fade along with a time; Or if it's transparent I give it a 1 in 10 chance of fading in during this iteration. If it's currently fading in or out I check to make sure it's on track and change the opacity of the div accordingly. Originally, I had the function call back to itself using setTimeout after the loop had gone through all the divs and changed their opacities appropriately. This caused an out of memory error (though, strangely, if I had any alerts in the function it didn't give me the error). So the version below has the code in a while loop to let it run for 20 seconds - this gives me the "a script...run slowly, do you want to continue the script?" message. So I have several questions: 1) First and foremost, why is my function causing out of memory/run slowly errors and what is the best way to fix that? 2) Is there a better way to code this effect (final result will be six lights fading in and out for a minute or so). 3)I'm not an experienced programmer, so any bad practices, ways to streamline, no no's, etc. that you see, please point out. I've only posted the script here - the page simple consists of three divs (id's grad0, grad1, grad2) and a call to the function copied here. Thanks in advance. Code: function commencez(){ //parent function to store var's var TimeToFade = 10000; theArray = new Array(2); var wrench = new Date().getTime(); for (var a=0; a<3; a++){ //fill the array with objects theArray[a] = document.getElementById("grad" + a); theArray[a].FadeState = -2; //start them transparent } function fader() { var check = new Date().getTime(); //stops the function after 30 seconds if( check <= wrench + 30000 ) { return; } for(var i=0; i<3; i++){ if (theArray[i].FadeState !=1 && theArray[i].FadeState != -1) { if( theArray[i].FadeState == 2) { theArray[i].FadeState = -1; theArray[i].FadeTimeLeft = TimeToFade; theArray[i].FadeBegan = new Date().getTime(); } if( theArray[i].FadeState == -2) { var rndm=Math.floor(Math.random()*11); if( rndm == 1) { theArray[i].FadeState = 1; theArray[i].FadeTimeLeft = TimeToFade; theArray[i].FadeBegan = new Date().getTime(); } } } if( theArray[i].FadeState == 1 || theArray[i].FadeState == -1) { var now = new Date().getTime(); since = now - theArray[i].FadeBegan; if( theArray[i].FadeTimeLeft <= since ) { theArray[i].style.opacity = theArray[i].FadeState == 1 ? '1' : '0.2'; theArray[i].style.filter = 'alpha(opacity = ' + (theArray[i].FadeState == 1 ? '100' : '20') + ')'; theArray[i].FadeState = theArray[i].FadeState == 1 ? 2 : 2; } theArray[i].FadeTimeLeft -= since; var howMuch = theArray[i].FadeTimeLeft / TimeToFade; if( theArray[i].FadeState == 1) { howMuch = 1-howMuch; theArray[i].style.opacity = howMuch; theArray[i].style.filter = 'alpha(opacity = ' + (howMuch*100) + ')'; } if( theArray[i].FadeState == -1) { theArray[i].style.opacity = howMuch; theArray[i].style.filter = 'alpha(opacity = ' + (howMuch*100) + ')'; } } } //close the for loop setTimeout( fader() , 500); //last thing fader does is recall itself after half a second } //close the fader function fader(); } //close parent function </script> I use a rotating image script on my website currently, but I'm taking a JavaScript class and started playing around my script to see if I can get it to display two random images at once, but never the same. Here's my script: Code: <!-- var images = new Array("<a href='index.php'><img src='images/image.gif' alt=''></a>","<a href='home.php'><img src='images/image.gif' alt=''/></a>); index = Math.floor(Math.random() * images.length); document.write(images[index]); // --> Where does the index come from? And how do I interpret images[index] if I were to read it out loud? I thought I could add ++ to the end of images.length to get it to display at least two images, but nada. I'm still new at this and would really appreciate if someone could talk me through this? Thanks! Hello Everyone! There are several other pages over a span of sites that deal with this matter, but none that seem to work for me. So I'm hoping you guys can help. I'm trying to get a set of rotating images to house a set of links that visitors can click on. Here's code I slapped together: Code: <script language="javascript" type="text/javascript"> var imgArray = new Array(); // Enter the names of the images below imgArray[0]="http://www.555.com/file.JPG"; imgArray[1]="http://www.555.com/file.JPG"; imgArray[2]="http://www.555.com/file.JPG"; // Set up URL array var URL = new Array(); URL[0] = "http://www.555.com"; URL[1] = "http://www.555.com"; URL[2] = "http://www.555.com"; var newImage = 0 ; var totalImg = imgArray.length ; var currentURL = (URL.length - 1); function cycleImg() { if (newImage == totalImg) { newImage = 0 ; } else { document.image.src = imgArray[newImage]; document.image.URL = URL[a] ; // set the time below for length of image display // i.e., "4*1000" is 4 seconds setTimeout("cycleImg()", 3*1000); newImage++; } } </script> <body onload="cycleImg();"> <div id="rotator_div"> <p style="text-align:center;"> <strong>Current Sponsors:</strong></p> <img id="rotating_img" src="http://www.555.com/file.JPG" name="image"/> </div> </body> Now it only loads the first image, and disappears; plus the image that does load, doesn't have the corresponding URL attached to it in as a link. Could anyone please help with the adjustments that I need to make to pull this off? Thanks very much in advance. Hello, I need the links to the rotating images to open in a new window. Is there an easy way to do this? Here is my code: [CODE] <script type="text/javascript"> var preload_ctrl_images=true; //And configure the image buttons' images he var previmg='left.gif'; var stopimg='stop.gif'; var playimg='play.gif'; var nextimg='right.gif'; var slides=[]; //FIRST SLIDESHOW //configure the below images and descriptions to your own. slides[0] = ["/pics/nav/home2/music-club_manatella.jpg", "", "/progs/main/manatella.pdf"]; slides[1] = ["/pics/nav/home2/teen-read-week2011.jpg", "", "/teens/teen-read-week2011.pdf"]; slides[2] = ["/pics/nav/home2/oceanway-express.jpg", "", "/lib/branches/OWY.html"]; slides[3] = ["/pics/nav/home2/jea-green.jpg", "", "/progs/jpl/home-energy-evaluation.html"]; slides[4] = ["/pics/nav/home2/childrens-summer-reading.jpg", "", "/kids/kids-summer-reading2011.pdf"]; slides[5] = ["/pics/nav/home2/teen-summer-reading.jpg", "", "/teens/teens-summer-reading2011.pdf"]; slides[6] = ["/pics/nav/home2/internet-safety.jpg", "", "/Training/Internet-Safety/internet-safety.html"]; slides.no_descriptions=1; //use for no descriptions displayed //use for no descriptions displayed //above slide show uses only the defaults </script> <script src="http://jpl.coj.net/common/javascripts/swissarmy.js" type="text/javascript"> </script> [CODE] [URL]http://jpl.coj.net Thank you so much for your help, Elbee Please help have a look at the scripts... Where's gone wrong that whenever an image fades out into 0, it reappears before another image comes out? I've wanted to make the image disappear shortly before a new image is loaded. I've worked on this and played around with the scripts, yet no finding... Please do tell me if you know the answer to it. Thanks. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script> window.onload = function(){ var pic = document.getElementById("pic"); document.getElementById("nextImageFading_btn").onclick = function(){nextImageFading();} } var img = new Array(); img[0] = "http://www.blogsdna.com/wp-content/uploads/2011/03/Google-labs.png"; img[1] = "http://thenextweb.com/socialmedia/files/2010/07/youtube_logo.png"; img[2] = "http://www.techlifeweb.com/facebook_logo.jpg"; img[3] = "http://hackingarticles.com/wp-content/uploads/gmail_logo_stylized.png"; var o = 100; var t; var p = 0; var f = 1; function nextImageFading(){ t = setInterval( function(){ pic.src = img[p]; pic.style.filter = "alpha(opacity="+o+")"; pic.style.MozOpacity = o/100; pic.style.opacity = o/100; o -= 1; if(o<=0){ clearInterval(t); if(p<img.length-1){ p = p+1; } else {p=0;} pic.src = img[p]; pic.style.filter = "alpha(opacity=100)"; pic.style.MozOpacity = 1; pic.style.opacity = 1; o = 100; } },f); } </script> </head> <body> <img id="pic" src="" style="width:400px; height:400px;" /> <br style="clear:both;" /> <a id="nextImageFading_btn" href="#">NEXT</a> </body> </html> Ok so i have wrote some code which can be seen he http://www.runningprofiles.com/members/include/test.php This works great but when i add the code to the page i want it on (include "include/test.php" for some reason the code does not work... the text is delayed and then lags behind the images.. this can been seen here http://www.runningprofiles.com/members/ I have no idea why its happening! Code for the code is Code: <html> <head> <title>http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q__26659912.html</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js"></script> <script type="text/javascript"> function advance() { $("#slideshow").cycle("next"); cycleCaption(); } var displayedIndex = 0 function cycleCaption() { $("#caption").children().each( function(index) { $(this).css("font-weight", (index==displayedIndex)? "bold" : "normal" ); }); displayedIndex = (++displayedIndex==$("#caption").children().length)? 0 : displayedIndex; } $(function() { $("#slideshow").cycle({ timeout: 0 }); $("img").each( function() { $("<div />").html($(this).attr("title")).appendTo($("#caption")); }); cycleCaption(); setInterval( "advance()", 2000 ); }); </script> </head> <body> <div id="slideshow" style="float: left;"> <img src="http://c0205112.cdn.cloudfiles.rackspacecloud.com/14882_jruqg6x4uu6frw2g872b.jpg" title="Aisling Cuffe Before Foot Locker" /> <img src="http://c0205112.cdn.cloudfiles.rackspacecloud.com/14879_mzcgn05auhs24fnsygc1.jpg" title="Foot Locker Ballerness" /> <img src="http://c0205112.cdn.cloudfiles.rackspacecloud.com/14880_u1npsmglw7b9t6hmoqhu.jpg" title="Foot Locker The Rocket" /> <img src="http://c0205112.cdn.cloudfiles.rackspacecloud.com/14887_9bblfhhvc0x66vebgjua.jpg" title="NCAA D2 Cro" /> <img src="http://c0205112.cdn.cloudfiles.rackspacecloud.com/14884_mud4ewe6uh6ihrrpux6g.jpg" title="NXN Recap and Results" /> <img src="http://c0205112.cdn.cloudfiles.rackspacecloud.com/14865_y1kt8vzejkvz25k075x2.jpg" title="Give Your " /> <img src="http://c0205112.cdn.cloudfiles.rackspacecloud.com/14877_1mlnygbenofquj5h3mcz.jpg" title="NCAA D2 XC Champ" /> <img src="http://c0205112.cdn.cloudfiles.rackspacecloud.com/14855_9g971maove1jyos0h9zk.jpg" title="Defending" /> <img src="http://c0205112.cdn.cloudfiles.rackspacecloud.com/14850_6u22ylfzym7sxq1zw8p8.jpg" title="NXN 121" /> </div> <div id="caption" style="float: left;"> </div> </body> </html> Not done any coding for a LONG time. I want to get the value of the opacity for a element. I'm using Nightly 9.0a1. Also, from what I have read Firefox should us this to SET the opacity style: Code: obj.style.opacity = opacity/100; But this does not see to work in the CSS. In the CSS the value ranges from 0 to 1. So 50% would be 0.5 My current function stops working before executing the alert command. I'm guessing i'm trying to get the style value wrong? Code: function fadeByid(objId) { if (document.getElementById) { obj = document.getElementById(objId); opacity = obj.style.opacity; alert(opacity); if (opacity >= 100) { setOpacity(obj, opacity); opacity -= 10; window.setTimeout("fadeByid('"+objID+"','"+opacity+")", 100); } } } Hi guys! I'm trying to make a div layer (id "tehz") fade in using Java. Problem is, it doesn't go through the animation, it just skips to the last stage. If I put an alert to show me the value of "cat" at every step it works just fine. Can anyone please tell me what's the matter? Code: function vis(cat) { if(cat<=90) { // alert(cat) document.getElementById("tehz").style.opacity=cat/100; document.getElementById("tehz").style.filter="alpha(opacity="+cat+")" cat=cat*1+1 setTimeout(vis(cat),1000); } } Hey everyone, For a site I'm currently working on I needed the index page to start out blacked out, have an animated logo fade in, then fade out again before the main page contents fading up all without redirecting etc. I used the following to do this and it works except for one thing. Once the overlay div has faded, it seems to take around 20-30 seconds before the main contents becomes usable. Any ideas for a fix? Code: <body style="overflow:hidden;" onload="MM_preloadImages('images/enter_o.png')"> <div id="overlay" ><img border="0" src="images/animatelogo.gif" alt="img" /></div> <script type="text/javascript"> /*<![CDATA[*/ function fade(o){ var oop=this,obj=document.getElementById(o.ID),img=obj.getElementsByTagName('IMG')[0]; this.obj=obj; var img=document.getElementById(o.ID).getElementsByTagName('IMG')[0]; img.style.top=this.wwhs()[1]/2-img.height/2+'px'; this.mS=o.Duration||1000; this.animate(img,new Date(),0,100,true); img.style.visibility='visible'; } fade.prototype={ animate:function(obj,srt,f,t,sc){ var oop=this,ms=new Date().getTime()-srt,now=Math.floor(sc=='s'?(t-f)*Math.sin(this.inc*ms)+f:sc=='c'?t-(t-f)*Math.cos(this.inc*ms):(t-f)/this.mS*ms+f); this.now=Math.max(now,f<0||t<0?now:0); obj.style.filter='alpha(opacity='+now+')'; obj.style.opacity=obj.style.MozOpacity=obj.style.WebkitOpacity=obj.style.KhtmlOpacity=now/100-.001; if (ms<this.mS){ this.dly=setTimeout(function(){ oop.animate(obj,srt,f,t,sc); },10); } else if (sc){ this.animate(this.obj,new Date(),100,0,false); } else { document.body.removeChild(obj); } }, wwhs:function(){ if (window.innerHeight) return [window.innerWidth-10,window.innerHeight-10,window.pageXOffset,window.pageYOffset]; else if (document.documentElement.clientHeight) return [document.documentElement.clientWidth-10,document.documentElement.clientHeight-10,document.documentElement.scrollLeft,document.documentElement.scrollTop]; return [document.body.clientWidth,document.body.clientHeight,document.body.scrollLeft,document.body.scrollTop]; } } setTimeout(function(){ new fade({ ID:'overlay', Duration:11500 }); },10); /*]]>*/ </script> <table class="mainbody" width="900" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td align="center"> <div style="position:absolute; left: 50%; top: 50%; margin: -197px 0 0 -300px; height: 394px; width: 600px; text-align:center;" /> <iframe src="http://player.vimeo.com/video/******44?title=0&byline=0&portrait=0&color=000000" width="600" height="328" frameborder="0"></iframe> <br /><br /><a href="films.php" class="entrytext"><img src="images/enter.png" id="Image1" onmouseover="MM_swapImage('Image1','','images/enter_o.png',1)" onmouseout="MM_swapImgRestore()"></a></div> </td> </tr> </table> </body> So as a breakdown, the page should load black, remain black as a logo fades into it, plays through and fades out, followed by the main content fading up and becoming usable. All this happens as desired except after the main content is visible it takes ages to become active as if the overlay is still there :-\ Thanks Hey everyone, What I need to do is have my website so when it loads on the homepage for the first time its starts of with a blank (specified color) background, then the logo fades in the middle, then a few seconds later that all fades away to reveal the website. Is this possible without forwarding to separate pages and without flash? Thanks all. Hi, I am having difficulty (tearing my hair out) with this problem. I have written a page as a learning experince for JavaScript. The page is here. The fade in works perfectly for ONLOAD and for ONMOUSEOVER but not for ONMOUSEOUT. The JavaScript code is as follows: Code: var d_opacity ; var e_element ; var t_timeout ; function fadeInElement(s_element_to_fade_in) { d_opacity = 0.25 ; e_element = document.getElementById(s_element_to_fade_in) ; (e_element.style).display = "" ; (e_element.style).opacity = d_opacity ; t_timeout = setTimeout("fadeIn()", 125) ; } function fadeIn() { if (d_opacity == 1.0) { clearTimeout(t_timeout) ; } else { d_opacity += 0.075 ; (e_element.style).opacity = d_opacity ; t_timeout = setTimeout("fadeIn()", 125) ; } } function fadeOutElement(s_element_to_fade_out) { e_element = document.getElementById(s_element_to_fade_out) ; d_opacity = (e_element.style).opacity ; t_timeout = setTimeout("fadeOut()", 125) ; // (e_element.style).display = "none" ; } function fadeOut() { if (d_opacity == 0.25) { clearTimeout(t_timeout) ; (e_element.style).display = "none" ; } else { d_opacity -= 0.075 ; (e_element.style).opacity = d_opacity ; t_timeout = setTimeout("fadeOutn()", 125) ; } } When I use the commented out line in fadeOutElement(), the menu disappears which says to me ONMOUSEOUT is being triggered correctly, but if I do the fading out code, it does nothing. Any help greatly appreciated. How am I able to have a gallery of images fading in and out as the background of a DIV? It's currently just a static background using CSS. You can view the HTML page in question he http://aksdesigns.co.uk/temp/template.html The DIV container is the one with the ID of #MainContent Code: #MainContent { width: 980px; height: 550px; margin: 0 auto; padding: 0px; background-image: url(images/Content-bg-1.jpg); background-repeat: no-repeat; background-position: top center; border-left: 2px solid #153365; border-right: 1px solid #FFF; } It probably couldn't be done using CSS be how could I achieve this with Javascript? So far I have this written up which does work well. However, the problem is if one toggles the fadeOut function while the fadeIn function is still in action. That causes the functions to collide and have to element being faded start flashing or freezing. Is there a simple way to prevent this? Thank you. Code: function fadeIn(elementId) { var element = document.getElementById(elementId); if(element.style.display === 'none') { element.style.display = 'block'; element.style.opacity = '0'; } if(element.style.opacity < 1) { var opacityFloat = parseFloat(element.style.opacity); element.style.opacity = opacityFloat + 0.1; setTimeout("fadeIn('" + elementId + "')", 50); } } function fadeOut(elementId) { var element = document.getElementById(elementId); if(element.style.opacity > 0) { var opacityFloat = parseFloat(element.style.opacity); element.style.opacity = opacityFloat - 0.1; setTimeout("fadeOut('" + elementId + "')", 50); } if(element.style.opacity == 0) { element.style.display = 'none'; } } I have a jQuery Slideshow script that i'm using and it's all done in 6 lines. Code: $(function(){ $('.fadein img:gt(0)').hide(); setInterval(function(){ $('.fadein :first-child').fadeOut() .next('img').fadeIn() .end().appendTo('.fadein');}, 3000); }); </script> I'm having a problem centering it on my website and keeping the images behind each other every time a picture changes. The CSS uses absolute positioning to hide the images behind each other. The fadeIn part of the CSS uses relative positioning. The CSS for the fading image slideshow is at the end of the css. Code: .fadein { position:relative; width:100%; height:300px; background-color:#000; overflow:hidden } .fadein img { position:relative; left:300px; width:auto; text-align:center; top:0px; } jonathaneiger.com Sorry, I'm new in javascript and i can't understand what's wrong with my code.. I've spent some time searching for the solution, but i give up. For some of you may it be just a piece of cake, so maybe you can look at this: Code: <script language="javascript"> var n_pics = 3; var current = 1; var opacity = 1; var opacity_IE = 100; function fade(how) { if(how==0) { if(opacity>0) { opacity = opacity - 0.1; } else return; } else { if(opacity<1) { opacity = opacity + 0.1; opacity_IE = opacity * 100; } else return; } document.getElementById('fade_show').style = 'opacity:'+opacity+'; filter:alpha(opacity='+opacity_IE+')'; //break_point 1 var temp = 'fade('+how+')'; setTimeout(temp, 1000); } function main_loop() { fade(0); //break_point 2 if(current == n_pics) { current = 1; } else { current = current + 1; } document.getElementById('fade_show').innerHTML = '<img src="images/fade_show/'+current+'.jpg" />'; fade(1); main_loop(); } </script> </head> <body onload="main_loop();"> fade(0) means to fade out, and fade(1) - to fade in. on IE i get 'Member Not found' on break_point 1 and too much recursion at breake_point 2 can you help me? ok ive been searching for a way to make it so when i click on a link it brings up an image or text box...and then when you click on another link on the same page that text box fades out and the new one fades in... i know how to make images fade in and out and i can make them overlap each other and everything...but making it so i can click either as many times as i want and they keep overlapping is a bit outside my scope sorry...but through my scowering of this forum i found an old post on this thread he http://codingforums.com/showthread.php?t=171655 where a user "spudhead" posted what i think im looking for...but it didnt work for me when i tried it... again, sorry if this isnt how you post idk im new here =/ i was going to post on the old thread but i wasnt sure if it would be answered... thanks for the responses... |