Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    302
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question making message disappear when stopping script

    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:

    Code:
    <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:

    Code:
    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:
    Code:
    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.

  • #2
    New Coder
    Join Date
    May 2004
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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..

  • #3
    Regular Coder
    Join Date
    Feb 2003
    Posts
    638
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Last edited by swmr; 05-02-2004 at 03:22 AM.
    hmm... ?

  • #4
    Regular Coder
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    302
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Smile

    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!

  • #5
    Regular Coder
    Join Date
    Feb 2003
    Posts
    638
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    hmm... ?

  • #6
    Regular Coder
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    302
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question

    Quote Originally Posted by swmr
    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
    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?
    Last edited by llizard; 05-02-2004 at 03:41 PM.

  • #7
    Regular Coder
    Join Date
    Feb 2003
    Posts
    638
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...
    hmm... ?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •