473,466 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Small fading bug

9 New Member
I have the following image fade in/out script which does work fine except for one bug, which is if you switch tabs and back again occasionally the image being faded out will hang in the background, half transparent and half opaque.

Here is the code that I am working with

Expand|Select|Wrap|Line Numbers
  1. var objIn;
  2. var objOut;
  3. var imgCont;
  4. var imgArr = new Array();
  5. var waitTime = 4; //The amount of time the script waits till it should move on to the next image (seconds)
  6. var fadespeed = 50; //The speed of the fading in and out (milliseconds)
  7. var lastindex = 0;
  8. var timer = 0;
  9.  
  10. function start(divElement){
  11.   imgCont = document.getElementById(divElement);
  12.   for(var i=0;i<imgCont.getElementsByTagName("img").length;i++){
  13.     imgArr[i] = imgCont.getElementsByTagName("img")[i];
  14.   }
  15.   if(lastindex>=(imgArr.length-1)){
  16.     timer = window.setTimeout("fadeinout(\""+imgArr[lastindex].id+"\", \""+imgArr[0].id+"\")", waitTime*1000);
  17.   }
  18.   else{
  19.     timer = window.setTimeout("fadeinout(\""+imgArr[lastindex].id+"\", \""+imgArr[lastindex+1].id+"\")", waitTime*1000);
  20.   }
  21. }
  22.  
  23. function pause(){
  24.   if(timer!=0){
  25.     window.clearTimeout(timer);
  26.     timer = 0;
  27.   }
  28. }
  29.  
  30. function resume(){
  31.   if(lastindex>=(imgArr.length-1)){
  32.     timer = window.setTimeout("fadeinout(\""+imgArr[lastindex].id+"\", \""+imgArr[0].id+"\")", waitTime*1000);
  33.   }
  34.   else{
  35.     timer = window.setTimeout("fadeinout(\""+imgArr[lastindex].id+"\", \""+imgArr[lastindex+1].id+"\")", waitTime*1000);
  36.   }
  37. }
  38.  
  39. function fadeinout(current, out){
  40.   objIn = document.getElementById(current);
  41.   objOut = document.getElementById(out);
  42.   fdio();
  43.   if(lastindex>=(imgArr.length-1)){
  44.     lastindex = 0;
  45.   }
  46.   else{
  47.     lastindex = lastindex + 1;
  48.   }
  49.   start(imgCont.id);
  50. }
  51.  
  52. function fdio(){
  53.   if(document.all){ //If statement is true then browser is IE
  54.     if(objIn.filters.alpha.opacity>0){
  55.       objIn.style.filter = 'alpha(opacity='+(objIn.filters.alpha.opacity-10)+')';
  56.       objOut.style.filter = 'alpha(opacity='+(objOut.filters.alpha.opacity+10)+')';
  57.       setTimeout("fdio(\""+objIn.id+"\", \""+objOut.id+"\")", fadespeed);
  58.     }
  59.   }
  60.   else{
  61.     if(objIn.style.opacity>0){
  62.       objIn.style.opacity = ((objIn.style.opacity*10)-1)/10;
  63.       objOut.style.opacity = ((objOut.style.opacity*10)+1)/10;
  64.       setTimeout("fdio(\""+objIn.id+"\", \""+objOut.id+"\")", fadespeed);
  65.     }
  66.   }
  67. }
P.S. The error can also occur when switching to different programs for a while, leaving the script running in the background
Apr 3 '12 #1
0 1266

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: ahmad | last post by:
Hi all, Is it possible to add a fading-in effect to the start of a java program. So when the program is started, it fads-in instead of pop-out. any help is appreciated, thanx
3
by: hypnotizes | last post by:
Has anyone seen the nice fading effect that involves one page, doing a fading transistion into another when you click on the link? Im trying to find the code for this effect. Any help!? An...
1
by: Deano | last post by:
Don't know if any of you chaps use www.basecamphq.com (a smart project management tool) but when you post a message up the entire post is highlighted in yellow, then fades until its disappears and...
2
by: Not Aaron | last post by:
I am wanting to have a couple small images "fade in" a couple seconds after a form loads. Didn't find an opacity feature for the picture box, any ideas? thx
4
by: Rich Sagall | last post by:
I am just learning Javascript and looking for some help with having a series of quotes that will fade in and out of the website. Thanks, Rich
8
by: Joe | last post by:
Hi trying to write some code to determine if user has large/small fonts set on PC thought this would work but it didn't Any suggestions??? Thanks Graphics g = Graphics.FromHwnd(this.Handle);
1
lolixpop
by: lolixpop | last post by:
Hi everybody thanks for reading! i have a few actionscript questions that i really need help on...any help would be greatly appreciated! Okay so i came upon this tutorial:...
2
by: Freightliner | last post by:
Hi, this script here displays a fading text message. I would like to display 3 different messages, let's say "Fading text 1", "Fading text 2", "Fading text 3". Also, is there a way to make it...
0
ThatThatGuy
by: ThatThatGuy | last post by:
This tutorial is intended to enlighten the power of XAML to build rich applications for Windows(WPF), Web(Silverlight) & Browser(XBAP). I will explain to you about building attractiveFading Glow...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.