SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    @alexstanford Alex's Avatar
    Join Date
    Apr 2004
    Location
    Jacksonville, Florida
    Posts
    757
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    How to delay a function?

    Hello everyone,

    I'm running a JavaScript powered tooltip on a project I'm working on. I would like to delay the tooltip by a couple hundred milliseconds. Here is the necessary code:

    Code:
    function doTooltip(evt,num) {
        if (!tooltip) return;
        if (t1) clearTimeout(t1);    if (t2) clearTimeout(t2);
        tipOn = true;
        // set colors if included in messages array
        if (messages[num][2])    var curBgColor = messages[num][2];
        else curBgColor = tipBgColor;
        if (messages[num][3])    var curFontColor = messages[num][3];
        else curFontColor = tipFontColor;
        if (ie4||ie5||ns5) {
            var tip = startStr + messages[num][0] + midStr + endStr;
            tipcss.backgroundColor = curBgColor;
             tooltip.innerHTML = tip;
        }
        if (!tipFollowMouse) positionTip(evt);
        else t1=setTimeout("tipcss.visibility='visible'",100);
    }
    Code:
    <area shape=circle coords="280,66,11" alt="" onmouseover="doTooltip(event,1)" onmouseout="hideTip()" />
    I am not very familiar with JavaScript, but I tried implementing a setTimeout as I found on Google which I could not get working.

    Can anyone tell me how to add a delay to the tooltip, please?

    Thank you in advance,
    Alex
    Alex Stanford @alexstanford tumblog about.me in fb G+ K
    TechTalkin The Premier Community for Technology Enthusiasts and Professionals
    Full Ambit Media Zero Sacrifice Web Design & Development; Made in the USA @fullambit in fb G+ K

  2. #2
    SitePoint Addict Phidev's Avatar
    Join Date
    Oct 2008
    Location
    Texas
    Posts
    204
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    setTimeout runs the function x milliseconds after the execution runs that line, but it keeps running code that follows, then after the x milliseconds have elapsed it runs the function in the setTimeout.

    When is the tooltip supposed to appear? If it is at certain event then you can do something like.

    onevent(setTimeout(doToolTip(arguments), milliseconds));

  3. #3
    @alexstanford Alex's Avatar
    Join Date
    Apr 2004
    Location
    Jacksonville, Florida
    Posts
    757
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Nevermind, solved.
    Alex Stanford @alexstanford tumblog about.me in fb G+ K
    TechTalkin The Premier Community for Technology Enthusiasts and Professionals
    Full Ambit Media Zero Sacrifice Web Design & Development; Made in the USA @fullambit in fb G+ K


Bookmarks

Posting Permissions

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