By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,961 Members | 1,665 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,961 IT Pros & Developers. It's quick & easy.

Image trails script in Firefox

KeredDrahcir
100+
P: 426
I have been given a script that will make the cursor work a bit like a comet, however the code deosn't work in Firefox. It has coditional statements which apply only to IE or NS.
I've tried the remove the IE conditions so that it runs that part of the code reguardless of the browser but it still doesn't work. I was wondering if someone could have a look at the code, and tell me what to do to it to make it work across multiple borwsers but mainly in Firefox.
Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript">
  2.  
  3. //Comment trail script- By Kurt (kurt.grigg@virgin.net)
  4. //Script featured on Dynamic Drive
  5. //Visit http://www.dynamicdrive.com for this script and more
  6.  
  7. colours=new Array('#ff0000','#00ff00','#ffffff','#ff00ff','#ffa500','#ffff00','#00ff00','#ffffff','ff00ff')
  8. n = 10;
  9. y = 0;
  10. x = 0;
  11. n6=(document.getElementById&&!document.all);
  12. ns=(document.layers);
  13. ie=(document.all);
  14. d=(ns||ie)?'document.':'document.getElementById("';
  15. a=(ns||n6)?'':'all.';
  16. n6r=(n6)?'")':'';
  17. s=(ns)?'':'.style';
  18. if (ns){
  19. for (i = 0; i < n; i++)
  20. document.write('<layer name="dots'+i+'" top=0 left=0 width='+i/2+' height='+i/2+' bgcolor=#ff0000></layer>');
  21. }
  22. if (ie)
  23. document.write('<div id="con" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
  24. if (ie||n6){
  25. for (i = 0; i < n; i++)
  26. document.write('<div id="dots'+i+'" style="position:absolute;top:0px;left:0px;width:'+i/2+'px;height:'+i/2+'px;background:#ff0000;font-size:'+i/2+'"></div>');
  27. }
  28. if (ie)
  29. document.write('</div></div>');
  30. (ns||n6)?window.captureEvents(Event.MOUSEMOVE):0;
  31. function Mouse(evnt){
  32. y = (ns||n6)?evnt.pageY+4 - window.pageYOffset:event.y+4;
  33. x = (ns||n6)?evnt.pageX+1:event.x+1;
  34. }
  35. (ns)?window.onMouseMove=Mouse:document.onmousemove=Mouse;
  36. function animate(){
  37. o=(ns||n6)?window.pageYOffset:0;
  38. if (ie)con.style.top=document.body.scrollTop;
  39. for (i = 0; i < n; i++){
  40. var temp1 = eval(d+a+"dots"+i+n6r+s);
  41.  
  42. randcolours = colours[Math.floor(Math.random()*colours.length)];
  43. (ns)?temp1.bgColor = randcolours:temp1.background = randcolours; 
  44. if (i < n-1){
  45.  var temp2 = eval(d+a+"dots"+(i+1)+n6r+s);
  46.  temp1.top = parseInt(temp2.top);
  47.  temp1.left = parseInt(temp2.left);
  48.  } 
  49. else{
  50.  temp1.top = y+o;
  51.  temp1.left = x;
  52.  }
  53. }
  54. setTimeout("animate()",10);
  55. }
  56. animate();
  57. // -->
  58. </script>
Any help would be much appriciated.
Jul 17 '11 #1
Share this Question
Share on Google+
2 Replies


acoder
Expert Mod 15k+
P: 16,027
That code looks ancient!

First of all, get rid of all the NS code (unless you want to support NS4 for some very strange, unfathomable reason).

Then make the code access elements using document.getElementById().

Look at the common events code for cross-browser compatibility which should be easy enough to integrate.

Add units to top/left, e.g. "px".

That should point you in the right direction. Also, check the error console to see what else needs fixing.

Alternatively, scrap it altogether and find a modern script that's written using document.getElementById() as standard.
Jul 19 '11 #2

KeredDrahcir
100+
P: 426
Thanks. I'll give that a go. I have noticed to age of the code. I'll let you know how I get on.
Jul 19 '11 #3

Post your reply

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