2011-08-29 73 views
0

我想在鏈接上存在hover至少1500毫秒或存在click後顯示image。如何在顯示圖像時實現這個最小週期懸停條件?在鏈接上懸停1500毫秒後顯示圖片

圖像應保持可見,直到鏈接或本身上懸停。當鼠標移出兩者時,&應該消失。我怎樣才能實現這個?提前致謝!

+3

你嘗試過什麼嗎? – FishBasketGordo

回答

4

http://jsfiddle.net/sSBxv/

$('a').click(function() { 

      alert(1); // alert on click 

     }) 

     .hover(function() { // when mouse is entering 

      var $this = $(this); 

      // set timeout, save timeout id on element to clear later 
      $this.data('timeout', setTimeout(function() { 
       $this.click(); // click after 1500ms 
      }, 1500)); 

     }, function() { // when mouse is leaving 

       clearTimeout($(this).data('timeout')); // stop the timeout 

     }); 
1

某事的作用...

$("#MyLinkSelectorId").hover(function() { 

     //Do anything you need to do here when it is clicked/hovered 

     setTimeout(function() { 

       //Do all of the other things here 

     }, 1500); 

}); 

轉出與點擊懸停或綁定多個事件採取兩種事件類型的護理。要隱藏圖像,可以使用.hide()方法在圖像上使用選擇器,或者如果瀏覽器支持,可以設置不透明度。

1
$("a.class").hover(function(){ //First parameter is onmouseenter, show the image 
    $("img").show(); 
}, function(){ //second is onmouseleave, set a timeout that will hide the image 
    setTimeout(function(){ 
     $("img").hide(); 
    }, 1500); 
}).click(function() { //on click, hide the image right away. 
    $("img").hide(); 
}); 
2

試試這個

var hoverTimer; 
$("linkSelector").hover(function() { 
    hoverTimer = setTimeout(function() { 
    $("imgSelector").show(); 
    }, 1500); 

}, function(){ 
    clearTimeout(hoverTimer); 
}).click(function(){ 
    clearTimeout(hoverTimer); 
    $("imgSelector").show(); 
}); 
1

因爲它看起來像你還沒有嘗試過的東西,我給你使用jQuery(請注意我的避風港最簡單的方法't tted this):

$("#idOfDiv").mouseover(function() { 
    setTimeout("alertMsg()",1500); 
}); 

function alertMsg() 
{ 
    alert('Ive been entered for 1500ms') 
} 

另外,如果你認真對待軟件開發,你應該能夠自己想出這個。