简体   繁体   English

我该如何做jquery悬停效果?

[英]how can i do this jquery hover effect?

i already made the usual buttons but i need to make the search button on the left menu on this website http://www.coolwebmasters.com/ 我已经做了通常的按钮,但是我需要在此网站http://www.coolwebmasters.com/上的左侧菜单中使搜索按钮

when i hover on the #profilename it disappears 当我将鼠标悬停在#profilename上时,它消失了

<div id="container">
<div class="prof"><a href="index.php"><img src="imgs/profile.png" alt="Messages"/>

</a></div>
</div>
<div  id="profilename">Name</div>



$(".prof").hover(function(){
$('#profilename').show('slide', {direction: 'left'}, 280); 
}, function() {
    $('#profilename').hide('slide', {direction: 'left'}, 280); 
});

It is because when you move the mouse out of the .prof element, the #profilename is hidden. 这是因为当您将鼠标移出.prof元素时,# #profilename被隐藏了。

Try 尝试

jQuery(function ($) {
    $('.prof').hover(function () {
        var $target = $('#profilename');
        clearTimeout($target.data('hoverTimer'));
        $target.stop(true, true).show('slide', {direction: 'left'}, 280);
    }, function () {
        var $target = $('#profilename');
        var timer = setTimeout(function () {
            $target.stop(true, true).hide('slide', {direction: 'left'}, 280);
        }, 200);
        $target.data('hoverTimer', timer);
    });

    $('#profilename').hover(function () {
        clearTimeout($(this).data('hoverTimer'));
    }, function () {
        $(this).stop(true, true).hide('slide', {direction: 'left'}, 280);
    });
});

Demo: Fiddle 演示: 小提琴

In the above solution, we give a 200ms time for the user to move from .prof to #profilename element, if so we clears the timeout thus the hiding of the element is prevented. 在上述解决方案中,我们为用户提供了200毫秒的时间,使其从.prof移至#profilename元素,如果这样,我们清除了超时,从而防止了该元素的隐藏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM