why won't this work?

October 12, 2010 at 02:08:26
Specs: Windows Vista
I found 2 neat javascript effects, but despite doing a lot of the same things, only 1 works in firefox.
this is a comet trailing cursor effect code (works in firefox):

<script language="JavaScript">
<!-- Mouse Comet 3 script by kurt.grigg [at]virgin.net -->
<!-- Get script at http://www.hypergurl.com
colours=new Array('#ffffff','#ff0000','#00ff00','#ffffff','#ff00ff','#ffa500','#fff000','#0000ff','#ffffff')
y = 0;
x = 0;
n6=(document.getElementById&&!document.all);
ns=(document.layers);
ie=(document.all);
d=(ns||ie)?'document.':'document.getElementById("';
a=(ns||n6)?'':'all.';
n6r=(n6)?'")':'';
s=(ns)?'':'.style';
n=(n6)?9:10;
if (ns){
for (i = 0; i < n; i++)
document.write('<layer name="dots'+i+'" top=0 left=0 width='+i/2+' height='+i/2+' bgcolor=#ff0000></layer>');
}
if (ie)
document.write('<div id="con" style="position:absolute;top:0px;left:0px"><div style="position:relative">');
if (ie||n6){
for (i = 0; i < n; i++)
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>');
}
if (ie)
document.write('</div></div>');

(ns||n6)?window.captureEvents(Event.MOUSEMOVE):0;
function Mouse(evnt){
y = (ns||n6)?evnt.pageY+4 - window.pageYOffset:event.y+4;
x = (ns||n6)?evnt.pageX+1:event.x+1;
}
(ns)?window.onMouseMove=Mouse:document.onmousemove=Mouse;

function animate(){
h=(ns||n6)?window.innerHeight:document.body.clientHeight;
w=(ns||n6)?window.innerWidth:document.body.clientWidth;
o=(ns||n6)?window.pageYOffset:0;
if (ie)con.style.top=document.body.scrollTop;
for (i = 0; i < n; i++){
var temp1 = eval(d+a+"dots"+i+n6r+s);
var randcolours = colours[Math.floor(Math.random()*colours.length)];
(ns)?temp1.bgColor = randcolours:temp1.background = randcolours;
if (i < n-1){
var temp2 = eval(d+a+"dots"+(i+1)+n6r+s);
temp1.top = parseInt(temp2.top);
temp1.left = parseInt(temp2.left);
}
else{
temp1.top = y+o;
temp1.left = x;
}
if ((y < h/10) || (y > h-h/10) || (x < w/10) || (x > w-w/10)){
var temp3 = eval(d+a+"dots"+0+n6r+s);
temp3.top = (y-25)+Math.random()*50;
temp3.left = (x-25)+Math.random()*50;
temp2.top = parseInt(temp3.top)+o;
temp2.left = parseInt(temp3.left);
}
}
setTimeout("animate()",30);
}
animate();
// -->

</script>

this one doesn't:

<script language="JavaScript">
<!-- Distributed by http://www.hypergurl.com -->
<!-- Mouse Attack by Kurt Grigg - http://www.btinternet.com/~kurt.gri...

var num=15;//Number of dots!
var vel=20;//Speed!
var col=new Array('#0080ff','#ffffff','#0000ff','#44ccff','#cc0033');//Dot colours, min 2!
var stopafter=60; //Stop and clear after x secondS!
//Nothing needs altering past here....................
var y=0;
var x=0;
var py=0;
var px=0;
var angle=0;
var distance=0;
var rep;
var ry=0;
var rx=0;
var tmr=null;
var n4=(document.layers);
var n6=(document.getElementById&&!document.all);
var ie=(document.all);
var o6=(navigator.appName.indexOf("Opera") != -1)?true:false;
var _d=(n4||ie)?'document.':'document.getElementById("';
var _a=(n4||n6)?'':'all.';
var _r=(n6)?'")':'';
var _s=(n4)?'':'.style';
var v=(n4)?"show":"visible";
var put=false;
stopafter*=1000;
if (n4||n6){
window.captureEvents(Event.MOUSEMOVE);
function mouse1(e){
if (put) return false;
y = e.pageY-window.pageYOffset;
x = e.pageX;
}
if (n4) window.onMouseMove=mouse1;
else document.onmousemove=mouse1;
}
if (ie||o6){
function mouse2(){
if (put) return false;
y = (ie)?event.clientY:event.clientY-window.pageYOffset;
x = event.clientX;
}
document.onmousemove=mouse2;
}
if (n4){
for (i=0; i < num; i++)
document.write('<layer name=dots'+i+' top=0 left=0 width='+i/3+' height='+i/3+' bgcolor=#ffffff></layer>');
}
else{
if (ie&&!o6){
document.write("<div id='outer' style='position:absolute;top:0px;left:0px'>");
document.write("<div style='position:relative'>");
}
for (i=0; i < num; i++)
document.write('<div id="dots'+i+'" style="position:absolute;top:0px;left:0px;width:'+i/3+';height:'+i/3+';background:#ffffff;font-size:1">.</div>');
if (ie&&!o6) document.write("</div></div>");
}
function pos(){
h=(ie)?document.body.clientHeight:window.innerHeight-20;
w=(ie)?document.body.clientWidth:window.innerWidth-20;
ry=Math.round(Math.random()*h);
rx=Math.round(Math.random()*w);
rep=Math.round(Math.random()*3);
if (rep == 3)ry=0;
if (rep == 2)ry=h;
if (rep == 1)rx=0;
if (rep == 0)rx=w;
py=ry;
px=rx;
}
pos();
function followleader(){
sy=(!ie)?window.pageYOffset:0;
sx=(!ie)?window.pageXOffset:0;
if (ie) outer.style.top=document.body.scrollTop;
for (i=0; i < num; i++){
randomcol=col[Math.floor(Math.random()*col.length)];
temp1=eval(_d+_a+"dots"+i+_r+_s);
temp1.visibility=v;
if (i < num-1){
temp2=eval(_d+_a+"dots"+(i+1)+_r+_s);
temp1.top=temp2.top;
temp1.left=temp2.left
}
else{
temp1.top=py+sy;
temp1.left=px;
}
if (n4)temp1.bgColor=randomcol;
else temp1.background=randomcol;
}
}
function bomb(){
ay=y-py;
ax=x-px;
angle=Math.round(Math.atan2(ay,ax)*180/Math.PI);
if (angle < 0) angle += 360;
dy=py-y;
dx=px-x;
distance=Math.floor(Math.sqrt(dx*dx+dy*dy));
go_y = Math.round(vel*Math.sin(angle*Math.PI/180));
go_x = Math.round(vel*Math.cos(angle*Math.PI/180));
py+=go_y;
px+=go_x;
if (distance < vel) pos();
followleader();
tmr=setTimeout("bomb()",20);
}
bomb();
function dsbl(){
v=(n4)?"hide":"hidden";
put=true;
x=0;
y=0;
setTimeout('clearTimeout(tmr)',stopafter+100);
}
setTimeout('dsbl()',stopafter);
//-->
</script>

the second script does the same thing as the first, except instead trailing the cursor, the comets fly at the cursor from all directions and chase the cursor until they hit it. Is it poeeible to get code 2 to work in firefox?


See More: why wont this work?

Report •

#1
October 12, 2010 at 03:03:24
Help protect your, and others', privacy by not posting email addresses.


=====================================
Helping others achieve escape felicity

M2


Report •
Related Solutions


Ask Question