Jump to content

Recommended Posts

here is the code for it

 

<script type='text/javascript'>

// SETUP VARIABLES
var path = mysite.com/imgs/';

var picture = new Array(
'img1.jpg',

'img2.jpg',

'img3.jpg',

'img4.jpg',

'img5.jpg',

'img6.jpg',

'img7.jpg',

'img8.jpg',

'img9.jpg',

'img10.jpg',

'img11.jpg',

'img12.jpg'
);

x=0;
function rotatePics()
{
for(x=0;x<=11;x+1)
{
	if(x==0)
	{
		if(document.getElementById('rotator').src==path+picture[0])
		{
			document.getElementById('rotator').src=path+picture[1];
		}
	}
	if(x==1)
	{
		if(document.getElementById('rotator').src==path+picture[1])
		{
			document.getElementById('rotator').src=path+picture[2];
		}
	}
	if(x==2)
	{
		if(document.getElementById('rotator').src==path+picture[2])
		{
			document.getElementById('rotator').src=path+picture[3];
		}
	}
	if(x==3)
	{
		if(document.getElementById('rotator').src==path+picture[3])
		{
			document.getElementById('rotator').src=path+picture[4];
		}
	}
	if(x==4)
	{
		if(document.getElementById('rotator').src==path+picture[4])
		{
			document.getElementById('rotator').src=path+picture[5];
		}
	}
	if(x==5)
	{
		if(document.getElementById('rotator').src==path+picture[5])
		{
			document.getElementById('rotator').src=path+picture[6];
		}
	}
	if(x==6)
	{
		if(document.getElementById('rotator').src==path+picture[6])
		{
			document.getElementById('rotator').src=path+picture[7];
		}
	}
	if(x==7)
	{
		if(document.getElementById('rotator').src==path+picture[7])
		{
			document.getElementById('rotator').src=path+picture[8];
		}
	}
	if(x==
	{
		if(document.getElementById('rotator').src==path+picture[8])
		{
			document.getElementById('rotator').src=path+picture[9];
		}
	}
	if(x==9)
	{
		if(document.getElementById('rotator').src==path+picture[9])
		{
			document.getElementById('rotator').src=path+picture[10];
		}
	}
	if(x==10)
	{
		if(document.getElementById('rotator').src==path+picture[10])
		{
			document.getElementById('rotator').src=path+picture[11];
		}
	}
	if(x==11)
	{
		if(document.getElementById('rotator').src==path+picture[11])
		{
			document.getElementById('rotator').src=path+picture[0];
			x=0;
		}
	}
setTimeout('rotatePics()',5000);
}
}

</script>


<center>

<img src='imgs/img1.jpg' id='rotator' onload='rotatePics();' />

</center>

 

last time i tried this code it crashed my IE7..

 

this code is just sposed to do a simple image swap based on which image is up.. and and have a 5 sec interval bewtween switches.. .but I've been working at this for somtime now and I can't seem to get it to work correcly..

 

I've gotten the imgs to swap.. but it will only swap like one time..

Link to comment
https://forums.phpfreaks.com/topic/115425-solved-need-help-with-rotator-function/
Share on other sites

well i think the for loop might be alil much so i've taken that out.. that seems to have kept IE from crashing but I'm still only getting it to switch.. one time..

 

whats the deal with that?

 

the logic says.. onload (after 5 secs) run the function

 

x=0 so switch the first image

 

increment x

 

then after 5 secs run the fucntion again.

 

but it never runs again....???

 

here is the updated code:

 

<script type='text/javascript'>

// SETUP VARIABLES
var path = mysite.com/imgs/';

var picture = new Array(
'img1.jpg',

'img2.jpg',

'img3.jpg',

'img4.jpg',

'img5.jpg',

'img6.jpg',

'img7.jpg',

'img8.jpg',

'img9.jpg',

'img10.jpg',

'img11.jpg',

'img12.jpg'
);

x=0;
function rotatePics()
{
	if(x==0)
	{
		if(document.getElementById('rotator').src==path+picture[0])
		{
			document.getElementById('rotator').src=path+picture[1];
		}
	}
	if(x==1)
	{
		if(document.getElementById('rotator').src==path+picture[1])
		{
			document.getElementById('rotator').src=path+picture[2];
		}
	}
	if(x==2)
	{
		if(document.getElementById('rotator').src==path+picture[2])
		{
			document.getElementById('rotator').src=path+picture[3];
		}
	}
	if(x==3)
	{
		if(document.getElementById('rotator').src==path+picture[3])
		{
			document.getElementById('rotator').src=path+picture[4];
		}
	}
	if(x==4)
	{
		if(document.getElementById('rotator').src==path+picture[4])
		{
			document.getElementById('rotator').src=path+picture[5];
		}
	}
	if(x==5)
	{
		if(document.getElementById('rotator').src==path+picture[5])
		{
			document.getElementById('rotator').src=path+picture[6];
		}
	}
	if(x==6)
	{
		if(document.getElementById('rotator').src==path+picture[6])
		{
			document.getElementById('rotator').src=path+picture[7];
		}
	}
	if(x==7)
	{
		if(document.getElementById('rotator').src==path+picture[7])
		{
			document.getElementById('rotator').src=path+picture[8];
		}
	}
	if(x==
	{
		if(document.getElementById('rotator').src==path+picture[8])
		{
			document.getElementById('rotator').src=path+picture[9];
		}
	}
	if(x==9)
	{
		if(document.getElementById('rotator').src==path+picture[9])
		{
			document.getElementById('rotator').src=path+picture[10];
		}
	}
	if(x==10)
	{
		if(document.getElementById('rotator').src==path+picture[10])
		{
			document.getElementById('rotator').src=path+picture[11];
		}
	}
	if(x==11)
	{
		if(document.getElementById('rotator').src==path+picture[11])
		{
			document.getElementById('rotator').src=path+picture[0];
			x=0;
		}
	}
x+1;
setTimeout('rotatePics()',5000);
}

</script>


<center>

<img src='imgs/img1.jpg' id='rotator' onload='setTimeout(\"rotatePics()\",5000);' />

</center>

here is the code for it

 

<script type='text/javascript'>

// SETUP VARIABLES
var path = mysite.com/imgs/';

var picture = new Array(
'img1.jpg',

'img2.jpg',

'img3.jpg',

'img4.jpg',

'img5.jpg',

'img6.jpg',

'img7.jpg',

'img8.jpg',

'img9.jpg',

'img10.jpg',

'img11.jpg',

'img12.jpg'
);

x=0;
function rotatePics()
{
for(x=0;x<=11;x+1)
{
	if(x==0)
	{
		if(document.getElementById('rotator').src==path+picture[0])
		{
			document.getElementById('rotator').src=path+picture[1];
		}
	}
	if(x==1)
	{
		if(document.getElementById('rotator').src==path+picture[1])
		{
			document.getElementById('rotator').src=path+picture[2];
		}
	}
	if(x==2)
	{
		if(document.getElementById('rotator').src==path+picture[2])
		{
			document.getElementById('rotator').src=path+picture[3];
		}
	}
	if(x==3)
	{
		if(document.getElementById('rotator').src==path+picture[3])
		{
			document.getElementById('rotator').src=path+picture[4];
		}
	}
	if(x==4)
	{
		if(document.getElementById('rotator').src==path+picture[4])
		{
			document.getElementById('rotator').src=path+picture[5];
		}
	}
	if(x==5)
	{
		if(document.getElementById('rotator').src==path+picture[5])
		{
			document.getElementById('rotator').src=path+picture[6];
		}
	}
	if(x==6)
	{
		if(document.getElementById('rotator').src==path+picture[6])
		{
			document.getElementById('rotator').src=path+picture[7];
		}
	}
	if(x==7)
	{
		if(document.getElementById('rotator').src==path+picture[7])
		{
			document.getElementById('rotator').src=path+picture[8];
		}
	}
	if(x==
	{
		if(document.getElementById('rotator').src==path+picture[8])
		{
			document.getElementById('rotator').src=path+picture[9];
		}
	}
	if(x==9)
	{
		if(document.getElementById('rotator').src==path+picture[9])
		{
			document.getElementById('rotator').src=path+picture[10];
		}
	}
	if(x==10)
	{
		if(document.getElementById('rotator').src==path+picture[10])
		{
			document.getElementById('rotator').src=path+picture[11];
		}
	}
	if(x==11)
	{
		if(document.getElementById('rotator').src==path+picture[11])
		{
			document.getElementById('rotator').src=path+picture[0];
			x=0;
		}
	}
setTimeout('rotatePics()',5000);
}
}

</script>


<center>

<img src='imgs/img1.jpg' id='rotator' onload='rotatePics();' />

</center>

 

last time i tried this code it crashed my IE7..

 

this code is just sposed to do a simple image swap based on which image is up.. and and have a 5 sec interval bewtween switches.. .but I've been working at this for somtime now and I can't seem to get it to work correcly..

 

I've gotten the imgs to swap.. but it will only swap like one time..

 

Try:

<script type="text/javascript">
   window.onload = function()
   {
      var path = "mysite.com/imgs/";
      var pictures = new Array(
                                   "img1.jpg", 
                                   "img2.jpg",
                                   "img3.jpg",
                                   "img4.jpg",
                                   "img6.jpg",
                                   "img7.jpg",
                                   "img8.jpg",
                                   "img9.jpg",
                                   "img10.jpg",
                                   "img11.jpg");

      var count = 0;
      var rotator = document.getElementById("rotator");

      rotator.onload = function()
      {
         setTimeout(rotatePics(), 5000);
      }

      function rotatePics()
      {
         if(count == 11)
         {
            count = 0;
            rotator.src = path + pictures[count];
         }
         else
         {
            count++;
            rotator.src = path + pictures[count];
         }
      }
   }
</script>

.
.
.

<img src='imgs/img1.jpg' id='rotator' />

 

One nitpick: the <center> element is deprecated.  Don't use it if you want valid code.

i got it working with my code..

 

I like yours its shorter.. but i'll just keep what i've got since it is working..

 

yea I feel you on the whole center thing but i'll conform to standards once they actually come up with some..

 

I find it halrious that it takes hacking most of the time to get code to work along with validation..

 

so until they all conform to a standard... I'll keep using deprecated code and hacks.

 

thanks for helping Nightslyr ,

 

ag3nt42

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.