473,320 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

event not working with firefox and NS7

the Code below captures the Mouse move event, while event isn´t defined
anywhere it still works in IE only, how can I define the event handler so it
can work with other browsers, Firefox mostly.
-------snipped code-------------
Ymouse = -50;
Xmouse = -50;

function Mouse(evnt) {
Ymouse=event.y-20;
Xmouse=event.x;
}
----------------------------------

the hole code:
<SCRIPT type="text/javascript">

Image0 = new Image();
Image0.src = "sailormoon.jpg";
Amount = 20;
Ymouse = -50;
Xmouse = -50;
Ypos = new Array();
Xpos = new Array();
Speed = new Array();
rate = new Array();
grow = new Array();
Step = new Array();
Cstep = new Array();
nsSize = new Array();
function Mouse(evnt) {
Ymouse=event.y-20;
Xmouse=event.x;
}
document.onmousemove=Mouse;
for (i = 0; i < Amount; i++) {
Ypos[i] = Ymouse;
Xpos[i] = Xmouse;
Speed[i] = Math.random()*4+1;
Cstep[i] = 0;
Step[i] = Math.random()*0.1+0.05;
grow[i] = 8;
nsSize[i] = Math.random()*15+5;
rate[i] = Math.random()*0.5+0.1;
}

document.write('<div style="position:absolute;top:0px;left:0px"><div
style="position:relative">');
for (i = 0; i < Amount; i++) {
document.write('<img id="si'+i+'" src="'+Image0.src+'"
style="position:absolute;top:0px;left:0px;filter:a lpha(opacity=90)">');
}
document.write('</div></div>');

function MouseBubbles() {
var hscrll=document.body.scrollTop;
var wscrll=document.body.scrollLeft;
for (i = 0; i < Amount; i++){
sy = Speed[i] * Math.sin(270 * Math.PI / 180);
sx = Speed[i] * Math.cos(Cstep[i] * 4);
Ypos[i] += sy;
Xpos[i] += sx;
if (Ypos[i] < -40) {
Ypos[i] = Ymouse;
Xpos[i] = Xmouse;
Speed[i] = Math.random() * 6 + 4;
grow[i] = 8;
nsSize[i] = Math.random() * 15 + 5;
}

document.getElementById("si"+i).style.pixelLeft = Xpos[i] + wscrll;
document.getElementById("si"+i).style.pixelTop = Ypos[i] + hscrll;
document.getElementById("si"+i).style.width = grow[i];
document.getElementById("si"+i).style.height = grow[i];

grow[i] += rate[i];
Cstep[i] += Step[i];
if (grow[i] > 24) grow[i] = 25;
}
setTimeout('MouseBubbles()', 10);
}
MouseBubbles();

</script>

wish you all a nice weekend , and many thank for the help
in the previous posts.

Best Regards
Jul 23 '05 #1
4 1879
Oscar Monteiro wrote:
the Code below captures the Mouse move event, while event isn´t defined
anywhere it still works in IE only, how can I define the event handler so it
can work with other browsers, Firefox mostly.
-------snipped code-------------
Ymouse = -50;
Xmouse = -50;

function Mouse(evnt) {
Add this line right after the function declaration:

var e = evnt || window.event;

then just use "e" rather than "event".
Ymouse=event.y-20;
Xmouse=event.x;


becomes:

Ymouse = e.y-20;
Xmouse = e.x;

You can also add support for older Netscape with:

Ymouse = e.y-20 || e.layerY-20;
Xmouse = e.x || e.layerX;

Untested, but see how you go.

--
Fred
Jul 23 '05 #2

"Fred Oz" <oz****@iinet.net.auau> escreveu na mensagem
news:42***********************@per-qv1-newsreader-01.iinet.net.au...
Oscar Monteiro wrote:
the Code below captures the Mouse move event, while event isn´t defined
anywhere it still works in IE only, how can I define the event handler so
it can work with other browsers, Firefox mostly.
-------snipped code-------------
Ymouse = -50;
Xmouse = -50;

function Mouse(evnt) {


Add this line right after the function declaration:

var e = evnt || window.event;

then just use "e" rather than "event".
Ymouse=event.y-20;
Xmouse=event.x;


becomes:

Ymouse = e.y-20;
Xmouse = e.x;

You can also add support for older Netscape with:

Ymouse = e.y-20 || e.layerY-20;
Xmouse = e.x || e.layerX;

Untested, but see how you go.

--
Fred


Thanks for helping me deffining the event handler Fred still lacks something
to track mouse movement .
Thanks anyway for the help given.
Jul 23 '05 #3
Oscar Monteiro wrote:
[...]

Thanks for helping me deffining the event handler Fred still lacks something
to track mouse movement .
Thanks anyway for the help given.


There was more than one issue, modified code below (original
commented out mostly)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>mouse move</title>
</head>
<body>
<span id="theSpot"></span>

<SCRIPT type="text/javascript">
Image0 = new Image();
// Image0.src = "sailormoon.jpg";
Image0.src = "a.jpg";
Amount = 20;
Ymouse = -50;
Xmouse = -50;
Ypos = new Array();
Xpos = new Array();
Speed = new Array();
rate = new Array();
grow = new Array();
Step = new Array();
Cstep = new Array();
nsSize = new Array();

docBody = document.getElementsByTagName('body')[0];
// debug
// spot = document.getElementById('theSpot');

function Mouse(event) {
var e = event || window.event;
// Ymouse= e.y-20;
// Xmouse= e.x;
// clientX/Y works in IE too, is OR needed still?
Ymouse= e.clientY-20 || e.y-20;
Xmouse= e.clientX || e.x;
}

document.onmousemove = Mouse;
for (i = 0; i < Amount; i++) {
Ypos[i] = Ymouse;
Xpos[i] = Xmouse;
Speed[i] = Math.random()*4+1;
Cstep[i] = 0;
Step[i] = Math.random()*0.1+0.05;
grow[i] = 8;
nsSize[i] = Math.random()*15+5;
rate[i] = Math.random()*0.5+0.1;
}

var aDiv = document.createElement('div');
aDiv.style.position = 'absolute';
aDiv.style.top = '0';
aDiv.style.left = '0';

var bDiv = document.createElement('div');
bDiv.style.position = 'relative';
for (i = 0; i < Amount; i++) {
var oImg = document.createElement('img');
oImg.id = 'si' + i;
oImg.src = Image0.src;
oImg.style.position = 'absolute';
oImg.style.top = '0';
oImg.style.left = '0';
oImg.style.filter = 'alpha(opacity=90)';

bDiv.appendChild(oImg);
}

aDiv.appendChild(bDiv);
docBody.appendChild(aDiv);

/*
// replaced with DOM methods above
document.write('<div style="position:absolute;top:0px;'
+ 'left:0px"><div style="position:relative">');
for (i = 0; i < Amount; i++) {
document.write('<img id="si'+i+'" src="'+Image0.src+'" '
+ 'style="position:absolute;top:0px;left:0px;filter: '
+ 'alpha(opacity=90)">');
}

document.write('</div></div>');
*/

function MouseBubbles() {
var hscrll=document.body.scrollTop;
var wscrll=document.body.scrollLeft;
for (i = 0; i < Amount; i++){
sy = Speed[i] * Math.sin(270 * Math.PI / 180);
sx = Speed[i] * Math.cos(Cstep[i] * 4);
Ypos[i] += sy;
Xpos[i] += sx;

// debug
// if (i<5)
// spot.innerHTML = Ypos.join(' ') + '\n' + Xpos.join(' ');

if (Ypos[i] < -40) {
Ypos[i] = Ymouse;
Xpos[i] = Xmouse;
Speed[i] = Math.random() * 6 + 4;
grow[i] = 8;
nsSize[i] = Math.random() * 15 + 5;
}

// pixelLeft not supported by Firefox, just use left
// (works in IE too)
// document.getElementById("si"+i).style.pixelLeft = Xpos[i]
// + wscrll;
// document.getElementById("si"+i).style.pixelTop = Ypos[i]
// + hscrll;
document.getElementById("si"+i).style.left = Xpos[i] + wscrll;
document.getElementById("si"+i).style.top = Ypos[i] + hscrll;
document.getElementById("si"+i).style.width = grow[i];
document.getElementById("si"+i).style.height = grow[i];

grow[i] += rate[i];
Cstep[i] += Step[i];

if (grow[i] > 24) grow[i] = 25;
}
setTimeout('MouseBubbles()', 10);
}
MouseBubbles();
</script>
</body>
</html>
--
Fred.
Jul 23 '05 #4
Fred Oz wrote:
Oscar Monteiro wrote:
[...]

Thanks for helping me deffining the event handler Fred still lacks
something to track mouse movement .
Thanks anyway for the help given.


There was more than one issue, modified code below (original
commented out mostly)

[...]
Tested and working in Safari too.
--
Fred
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Lachlan Hunt | last post by:
Hi, I've been looking up lots of documentation and trying to work out a cross-platform method of capturing a keyboard event and working out which key was pressed. From what I can find, there...
5
by: Mark Szlazak | last post by:
Apparently there is a textarea onscroll event bubbling bug in Firefox and Mozilla: https://bugzilla.mozilla.org/show_bug.cgi?id=229089 I'm trying to check for this bug with the following...
10
by: Noozer | last post by:
Is it possible to detect where on a page the click occurred when the OnClick event of the BODY tag is fired? Thx
1
by: Jordan | last post by:
I set the cursor property to change to the "hand" when the user performs an "onmouseover" event on a hyperlink object. This does work correctly with Internet Explorer, however, with Netscape and...
6
by: RC | last post by:
I am try to detect the mouse pointer by var event = window.event; var x = event.pageX; var y = event.pageY; This is working fine in IE, but in Netscape/Firefox where event return...
1
by: nebulus | last post by:
I'm working on a web app that under normal circumstances will be happy with the Session_OnEnd event, but when a user leaves a page by closing the browser by either Alt+F4 or just hitting the "X",...
33
by: buss123 | last post by:
Hi all, combo box script code was working in IE perfectly with all modes but OnChange event was not working in FireFox(editable mode, if we select valuese that combo box values r...
5
by: suresh_nsnguys | last post by:
Hi, I am facing one problem in embed flash object.i am displaying the flash (.swf file) using embed tag<embed> in IE.i want to display the alert box when user click the mouse over the flash .i am...
1
by: manojsharma | last post by:
hey can anybody tell me y my onkeyup event is not working in firefox.. it is working fine in IE... code <input type="text" name="oddteam" size="1" value="1" ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.