...

View Full Version : making message disappear when stopping script



llizard
05-01-2004, 07:50 PM
I am a rank beginner at Javascript. I'm not sure if this is a CSS or a Javascript question but as it concerns stopping a cursor trail script, I will pose it here in this forum.

I have placed the following on a page that has one of those irritating cursor trail scripts:




<a href="#" onclick="document.onmousemove=meander; return false;" title="Start trailing"><i>Start</i> the senseless cursor trail.</a> |

<a href="#" onclick="document.onmousemove=null; return false;" title="Stop trailing!"><i>Stop</i> the senseless cursor trail.</a>


This works perfectly to start and stop the script but when the script is stopped, the cursor trail message is still showing - static but visible.

How would I go about making the message invisible when the script is stopped?

Is it by changing the visibility from visible to hidden on the style for the cursor trail? Or might I have to set the message value to show nothing and then add the value of addit when the cursor trail starts? I foolishly imagined that the following might work:



var message=""
var addit="cursor trail... "

if (document.onmousemove=meander) {
message + addit;
}


That resulted in a big mess so (still shooting in the dark) instead of the above nonfix, I tried adding the following:


if (document.onmousemove=null) {
document.getElementById.spanstyle.visibility = "hidden";
}

Naturally, that didn't work either. Help?


The page with the cursortrail script on it is here (http://ejmtph.crosswinds.net/links.html).

rechocto
05-01-2004, 10:06 PM
i am even more of a beginner than you, but....

if (document.onmousemove=null) {
document.getElementById.spanstyle.visibility = "hidden";
}

should probably be

if (document.onmousemove=null) {
document.form name.spanstyle.visibility=hidden
}

though i dunno if that would make a difference, it usually does..

swmr
05-02-2004, 03:49 AM
This should do it:

1. add this to the style:
.hideMe{display:none}

2. add this in one of the script tags:
function toggleAnnoyance(cls){var spn, ic;
spn = document.getElementsByTagName("SPAN");
for(var I = 0; I < spn.length; I++){
ic = spn[I].className;
if(ic == "spanstyle" || ic == "hideMe"){spn[I].className = cls;}}
}

3. add this to "stop meandering":
onclick=\"document.onmousemove = null;toggleAnnoyance('hideMe')\"

& this to "meander":
onclick=\"document.onmousemove = meander;toggleAnnoyance('spanstyle'); return false;\"


Edit: fixed a problem w/ the function & simplified it some... change everything above, except for the style.

llizard
05-02-2004, 06:36 AM
Many thanks, swmr! It works perfectly.

Just one question though, I don't quite understand about when to add return true; or return false; (I am having trouble grasping the significance of "true" and "false")

But it looks like you are recommending that there be no return at all for onclick=\"document.onmousemove = null;. Am I misreading?

Many thanks again for the fix!

swmr
05-02-2004, 06:50 AM
Actually, the only thing I added to each event was toggleAnnoyance(...), but the return false just prevents that link from being visited...

liorean has done a nice job of explaining the concept of return values here (http://codingforums.com/showthread.php?t=32992)

llizard
05-02-2004, 04:32 PM
Actually, the only thing I added to each event was toggleAnnoyance(...), but the return false just prevents that link from being visited...

liorean has done a nice job of explaining the concept of return values here (http://codingforums.com/showthread.php?t=32992)

Thanks again swmr.

As it happens, I had already looked at liorean's post when I was googling about return false and return true- that was one of the places where I almost caught a glimmering of understanding. I have reread it again and the glimmer is almost, but not quite, a light.


edit to add:
I've just done a little more staring at explanations of true, false and null... I see that anything that is false has a value of 0 and anything that is true has any value other than 0. Anything that is null has no value at all.

Excuse me if this is a really dumb question: Does this mean that for onclick=document.onmousemove=null;, there is no need to add a return because null has no value anyway?

swmr
05-02-2004, 05:54 PM
From what I understand, assigning a null value to an event overwrites its call.

You might try experimenting with simple functions and alerts to see what gets returned; that's helped my basic understanding, anyway... ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum