SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Mouseout Delay

  1. #1
    SitePoint Zealot
    Join Date
    Feb 2009
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mouseout Delay

    Hi,

    I currently have this code which does something when I mouseout:

    Code:
    <span class="bar1 run" onmouseover="mouseOver1()" onmouseout="mouseOut1()"></span>
    I would like to change it so that there is a delay between the mouseout and the funtion. How can this be done?

    Thanks

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    function delayedMouseOut1() {
        setTimeout(mouseOut1, 2000);
    }
    If your function makes use of the this keyword, a slightly different approach is needed.

    Code:
    function delayedMouseOut1() {
        var that = this;
        setTimeout(function() {
            mouseOut1.call(that);
        }, 2000);
    }

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2009
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks. I have now ended up with this jquery code:

    Code:
     $(document).ready(function(){
    
        $("#barcode span").hover(
          function () {
    		$(this).addClass("barover");
          }, 
          function () {
    		$(this).removeClass("barover");
          }
        );
      });
    How would I add a timeout to this so that there is only a delay with the removeClass?


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
  •