ag3nt42 Posted July 18, 2008 Share Posted July 18, 2008 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.. Quote Link to comment https://forums.phpfreaks.com/topic/115425-solved-need-help-with-rotator-function/ Share on other sites More sharing options...
ag3nt42 Posted July 18, 2008 Author Share Posted July 18, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/115425-solved-need-help-with-rotator-function/#findComment-593383 Share on other sites More sharing options...
KevinM1 Posted July 18, 2008 Share Posted July 18, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/115425-solved-need-help-with-rotator-function/#findComment-593388 Share on other sites More sharing options...
ag3nt42 Posted July 18, 2008 Author Share Posted July 18, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/115425-solved-need-help-with-rotator-function/#findComment-593435 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.