/    Sign up×
Community /Pin to ProfileBookmark

um hello!!

i have found this code in the JavaScript source:
[url]http://javascript.internet.com/miscellaneous/fly.html[/url]

and i like it!! :p

only i am unable to correctly follow the instruction there ?

i dont know how to make sure if i entered the correct path for the images ive downloaded..

where should i put the images??

also im wonderin’ if its possible for the fly to move on the browser not just the page..

to post a comment
JavaScript

16 Comments(s)

Copy linkTweet thisAlerts:
@LeeUApr 25.2006 — You just need to put the path where any of the images are located, i.e.,
[CODE]dir[-2]="[COLOR=Red]/yourPathHere/[/COLOR]Mosca_5.gif";[/CODE]

The images can be placed in the same directory as the page. HOwever, it would be better if they were in a separate directory.

You can't run scripts outside of the browser window. The fly can't go on the "chrome" of the browser. (Would be pretty scary if you could ...)
Copy linkTweet thisAlerts:
@elainebludfairyauthorApr 26.2006 — haha LeeU.. i wanna scare someone!! :p

niwei thanks.. now it is working!! ?

...

p.s.

the Fly seems not to be working on Firefox!! ?

i mean its not behaving like a Proper Fly..

looks dead..

can someone make it also move on Firefox!!

IE & Firefox!!

pleeeeese!!

i love that Fly!!
Copy linkTweet thisAlerts:
@elainebludfairyauthorApr 27.2006 — pleeeeeeeeeeeeeeeeeeeeeeeeeeeeeeese!!!!!!!!!

is it really for IE only??????!!
Copy linkTweet thisAlerts:
@Black_CatApr 27.2006 — Well - on the page it came from it does say its IE only!!
Copy linkTweet thisAlerts:
@elainebludfairyauthorApr 27.2006 — ?

i know.. someone out there knows!!
Copy linkTweet thisAlerts:
@felgallApr 27.2006 — Half the code in the script is for Netscape 4.

The other half works fine with IE and Opera.

The script does not work with other browsers as it uses version 4 proprietary code rather than version 5+ standard code.
Copy linkTweet thisAlerts:
@elainebludfairyauthorApr 27.2006 — er..

can you make a code for that Fly that uses 5+ standard code ? ??

pleeeese!!!!!!!!!!!!
Copy linkTweet thisAlerts:
@elainebludfairyauthorApr 29.2006 — hello ? !!

um.. okey.. im sorry..

is it possible to resolve it using a code fix or its really needed to change the whole code into a more standard one to be able for it to also work on firefox??

please!! anyone..
Copy linkTweet thisAlerts:
@userloginApr 29.2006 — [CODE]var answer = (bear.indexOf('does a bear'))? true : false;[/CODE]

Good way to learn JS.
Copy linkTweet thisAlerts:
@elainebludfairyauthorApr 30.2006 — userlogin ellooo!! ?

THANK YOU for the code.. only..

er.. :o

please tell me please how should i use it!!

should i add it on the fly.js file like this...

[CODE]------------------------------------------------
/*
Original: Stefano Occhetti
E-mail: [email protected]
Web Site: http://www.geocities.com/starnuto_di_topo_2001

*/

var answer = (bear.indexOf('does a bear'))? true : false;
var ns = (document.layers)?1:0;

/*
Button:
this code is to show a "button" to switch
the fly ON/OFF.
It is always shown on the frame's
bottom-right corner.
------------------------------------------------
*/
var imgwidth=40; // Image width
var imgheight=40; // Image height

var button = Array(); // to pre-cache images
button[0]=new Image();
etc.[/CODE]


i know it seems annoying to add a moving fly on webpages (ive been told this actually) but the site im creating is only for a few friends who need cheering up.. its also my first time creating a site so its a learning thing for me too..
Copy linkTweet thisAlerts:
@Orc_ScorcherApr 30.2006 — Wake up, ok? That "code" was the answer to your question whether the code can be changed to work with Firefox. If you still don't get it, read [URL=http://forum.wordreference.com/showpost.php?p=683693&postcount=2]this[/URL].
Copy linkTweet thisAlerts:
@netbuddyApr 30.2006 — sorry, I couldnt help myself....

You will have to test for the browser specific function.

for example, the following conditional statement 'if(document.getElementById)' returns true if the browser supports this method of acccessing the particular document object.
Copy linkTweet thisAlerts:
@felgallApr 30.2006 — To convert the code to work with modern browsers you replace all of the document.all and document.layer references with document.getElementById
Copy linkTweet thisAlerts:
@elainebludfairyauthorMay 01.2006 — ..sorry

..thanks
Copy linkTweet thisAlerts:
@felgallMay 01.2006 — Rewritten to work on modern browsers (not much of the original left apart from the images).

/*
Original: Stefano Occhetti
E-mail: [email protected]
Web Site: http://www.geocities.com/starnuto_di_topo_2001

Rewritten by Stephen Chapman for use with version 5+ browsers
http://javascript.about.com

*/

/* cross browser functions copyright Stephen Chapman */
function mouseX(evt) {if (!evt) evt = window.event; if (evt.pageX) return evt.pageX; else if (evt.clientX)return evt.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft); else return 0;}
function mouseY(evt) {if (!evt) evt = window.event; if (evt.pageY) return evt.pageY; else if (evt.clientY)return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); else return 0;}
function pageWidth() {return window.innerWidth != null? window.innerWidth: document.body != null? document.body.clientWidth:null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.body != null? document.body.clientHeight:null;}
function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;}
function posTop() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;}
function posRight() {return posLeft()+pageWidth();} function posBottom() {return posTop()+pageHeight();}
function objWidth(objectID) {var obj = document.getElementById(objectID); if(obj.offsetWidth) return obj.offsetWidth; if (obj.clip) return obj.clip.width; return 0;}
function objHeight(objectID) {var obj = document.getElementById(objectID,0); if(obj.offsetHeight) return obj.offsetHeight; if (obj.clip) return obj.clip.height; return 0;}
/*
Button:
this code is to show a "button" to switch
the fly ON/OFF.
It is always shown on the frame's
bottom-right corner.
------------------------------------------------
*/
var imgwidth=40; // Image width
var imgheight=40; // Image height

var button = Array(); // to pre-cache images
button[0]=new Image();
button[0].src="img/Mosca_OFF.gif";
button[1]=new Image();
button[1].src="img/Mosca_ON.gif";

//Initialize some variables to make the button always to appear on the frame's bottom-right corner
document.write("<div id='FlyOnOff' style='position:absolute; visibility:show; left:235px; top:-50px; z-index:2'><img onclick='showhideAnimation()' id='Button' src='"+button[0].src+"' width='"+imgwidth+"' height='"+imgheight+"' border='0'></div>");

// Moves the button in the right position
function checkLocation() {
document.getElementById('FlyOnOff').style.left = (posRight() - imgwidth - 30) + 'px';
document.getElementById('FlyOnOff').style.top = (posBottom() - imgheight - 20) + 'px';
}

/*
Fly:
this code provides some facilities
to show a fly moving on the screen.

<i> </i>The fly does not actually follow the
<i> </i>mouse, but a "Dot" (not shown!).
------------------------------------------------
*/



document.onmousemove=getMousePosition;


var Dot_Ro=60; //Dot's distance from the mouse pointer
var Dot_Theta=0; //Dot's initial angle
var Dot_Direction=1; //Dot's direction (1=clockwise)
var Dot_x=0; //Dot's original position
var Dot_y=0;
var picX = 20; //Fly's coords.
var picY = 100;
var mX = 0; //Mouse coords.
var mY = 0;
var step = 10; //Pixels
var speed = 100;//u-seconds


// Dir specifies the right picture;
// img pre-caches images.
var dir = Array();
dir[-4]="Mosca_3.gif";
dir[-3]="Mosca_4.gif";
dir[-2]="Mosca_5.gif";
dir[-1]="Mosca_6.gif";
dir[0]="";
dir[1]="Mosca_2.gif";
dir[2]="Mosca_1.gif";
dir[3]="Mosca_8.gif";
dir[4]="Mosca_7.gif";

var img = Array();
for (var i=-4; i&lt;5; i++){
img[i]=new Image();
img[i].src="img/"+dir[i];
}

// Some HTML code to show the fly.

<i> </i>document.write("&lt;div id='FlyDiv' style='position:absolute'&gt;&lt;img id='flyImg' src=" + img[1].src + "&gt;&lt;/div&gt;");


function getMousePosition(e) {
mY=mouseY(e);
mX=mouseX(e);
}


//Shows or hides the fly when the "button" is pressed
function showhideAnimation() {
document.getElementById('FlyDiv').style.visibility = document.getElementById('FlyDiv').style.visibility=="hidden"?"visible":"hidden";
document.getElementById('Button').src = document.getElementById('FlyDiv').style.visibility=="hidden"?button[1].src:button[0].src;
}


// Moves the fly around the screen
function moveFly() {
checkLocation()
// moves the fly in a new position...
Dot_Theta+=Dot_Direction*Math.PI/15;
Dot_x=mX+Dot_Ro*Math.cos(Dot_Theta);
Dot_y=mY+Dot_Ro*Math.sin(Dot_Theta);
var mult = (Dot_x - picX &lt; 0)? -1:1;
var alpha = Math.atan((Dot_y-picY) / (Dot_x-picX));
picX += (mult * step * Math.cos(alpha));
picY += (mult * step * Math.sin(alpha));
document.getElementById('FlyDiv').style.left = (picX - objWidth('flyImg')/ 2) +'px';
document.getElementById('FlyDiv').style.top = (picY - objHeight('flyImg')/ 2) + 'px';

<i> </i>// ... and changes the image.
<i> </i>alpha=(-180*alpha/Math.PI)+22.5;
<i> </i>var i = 0;
<i> </i>while(alpha&gt;-Math.PI+45*i)i++;
<i> </i>document.getElementById('flyImg').src = img[mult*(i+1)].src;
<i> </i>}

function ChangeDotDirection() {
Dot_Direction=-Dot_Direction;
Dot_Theta+=Math.PI;
}

setInterval('moveFly()', speed);
setInterval('ChangeDotDirection()', speed*50);
Copy linkTweet thisAlerts:
@elainebludfairyauthorMay 01.2006 — felgall.. thank you so much!!

thank you a milliooooooooooooooon much!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

sorry for being stupid i dont really know..

thank you again ? !!
×

Success!

Help @elainebludfairy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...