2013-03-26 56 views
-1

我有一個圖標,當我把鼠標懸停在它上面顯示一個鏈接的div。用戶應該能夠點擊此鏈接,但當鼠標離開圖標時,它會消失。有誰知道我可以如何防止這種情況發生?Div與鏈接消失之前,我可以使用它(jQuery的隱藏/顯示)

代碼:

$('.div1').hover(function(e){ 
    e.preventDefault(); 
    e.stopPropagation(); 
    $(this).next().show('fast'); 
}, 
function(e){ 
    e.preventDefault(); 
    e.stopPropagation();  
    $(this).next().hide('fast'); 
}); 

我做了一個的jsfiddle,藉以說明問題:

http://jsfiddle.net/2wrjG/5

回答

0
$('.domaininfo').hover(function (e) { 
    e.preventDefault(); 
    e.stopPropagation(); 
    $(this).next().show('fast'); 
}, 
function (e) { 
    e.preventDefault(); 
    e.stopPropagation(); 
    $('.domain-info-window').hover(function (e) { 
     e.preventDefault(); 
     e.stopPropagation(); 
    }, 
    function (e) { 
     e.preventDefault(); 
     e.stopPropagation(); 
     $(this).hide('fast'); 
    }); 
}); 

DEMO HERE

0

的問題是,你離開IMG標籤當你嘗試點擊鏈接。我建議將所有內容都包裹起來,然後在這個包裝上調用懸停。

這裏工作小提琴:http://jsfiddle.net/2wrjG/2/

$('.wrapper').hover(function (e) { 
    e.preventDefault(); 
    e.stopPropagation(); 
    $(this).children('a').show('fast'); 
}, 

function (e) { 
    e.preventDefault(); 
    e.stopPropagation(); 
    $(this).children('a').hide('fast'); 
}); 

HTML-部分:

<div class="wrapper"> 
<img class="domaininfo" src="http://domeinwinkel.sitestatus.nl/gfx/itje.png"> 
<a class="domain-info-window" id="domain-info-window-2" href="#"> 
Is deze domeinnaam bij een andere provider geregistreerd maar wil je profiteren van de voordelen van Domeinwinkel? Verhuizen naar Domeinwinkel is snel geregeld! 
</a> 
</div> 

CSS:

.domaininfo { 
    position: relative; 
    top: 0px; 
    left: 0px; 
} 
0

,當你將鼠標懸停在圖像的DIV所示。 如果你想鏈接消失,只有當你點擊它,我想這可以幫助你。

enter code here 

$('.domaininfo').hover(function (e) { 
      e.preventDefault(); 
      e.stopPropagation(); 
      $(this).next().show('fast'); 
    },function (e) { 
      e.preventDefault(); 
      e.stopPropagation(); 
      $('.domain-info-window').click(function (e) { 
       $(this).hide(); 
      }); 
     });