2009-07-26 64 views
0

我试图让一个sIFR文本出现时,悬停在一个div,有一些延迟。jQuery和sIFR。在悬停 - 延迟和显示

标记是这样的,好几次:

<div class="box"> 
    <div class="text"> 

     <h6>sIFR Text</h6> 

    </div> 
</div> 

这段代码是干什么的伎俩(从隐藏到sIFR的悬停),但无延时:

$(document).ready(function() {  

     $('.text').hide(); 

     $('.box').mouseover(

     function() { 

       $(this).children('.text').show(); 

       //sIFR code : 
        sIFR.replace(rockwell, { 
          selector: 'h6', 
         css: [ 
          '.sIFR-root { color:#FFFFFF; font-size: 1.2em; text-transform: uppercase }', 
          'a {color: #333333; text-decoration: none;}', 
          'a:hover {color: #333333;text-decoration:underline;}' 
          ], wmode: "transparent" 
        } 
        ); //sIFR ends 

     }); 



     $('.box').mouseout(

     function() { 
       $(this).children('.text').hide(); 
      } 
    ); 
}); 

我试图用在hoverIntent插件,加载它,并用它这样的,但它似乎并不工作:

$(document).ready(function() {   

     $('.text').hide(); 

     $('.box').hoverIntent(

       function() { 

        $(this).children('.text').show(); 

     //sIFR code should go here 
        sIFR.replace(rockwell, { 
          selector: 'h6', 
         css: [ 
          '.sIFR-root { color:#FFFFFF; font-size: 1.2em; text-transform: uppercase }', 
          'a {color: #333333; text-decoration: none;}', 
          'a:hover {color: #333333;text-decoration:underline;}' 
          ], wmode: "transparent" 
        } 
        ); //sIFR ends 

       }, 

       function(){ 

        $(this).children('.text').hide(); 

        } 
     ); 

}); 

你能指出任何替代方案? 也许setTimeout是一个很好的选择,但我之前使用过它,我不确定我应该在哪里放置它。

感谢您的任何提示。

回答

1

你可以使用setTimeout。

$(document).ready(function() {   

     //delcare a variable to hold the timeout 
     var to; 

     $('.text').hide(); 

     $('.box').mouseover(

       function() { 

        $(this).children('.text').show(); 

        // do sIFR code after 1000 milliseconds 
        to = setTimeout(function() { /* sIFR code goes here */ }, 1000); 

       }); 



     $('.box').mouseout(

       function() { 
         // If mouseout happens before the delay ends 
         // you probably don't want sIFR code to run. 
         clearTimeout(to); 


         $(this).children('.text').hide(); 
       } 
     ); 
}); 
+0

极其整洁,谢谢! – Peanuts 2009-07-26 13:55:34