문제

So I'm trying to something like, where you hover over text and something appears right beside it:

$('.lang1').mouseenter(function() { 
        $('.lang1 span').fadeTo('fast', 1);
    });

$('.lang1').mouseleave(function() {
        $('.lang1 span').fadeTo('fast', 0);
    });

But once I remove my mouse over it it still appears, very faint but it's visible. It works exactly as intended but it just doesn't lose it's opacity completely, you have to keep hovering and moving your mouse away from it to lose it's opacity completely.

Anyone have suggestions?

CSS:

span {
    opacity: 0;
}

HTML:

<li class="lang1">HTML     <span>Pretty good at</span></li>
도움이 되었습니까?

해결책

I'd just use fadeIn('fast') and fadeOut('fast') for the fading effect and then use a callback to hide the element. Something like this:

$('.lang1').mouseleave(function() {

        $('.lang1 span').fadeOut('fast', function() { $(this).hide(); });
});

I think the simpler alternative would be to change the CSS to display:none; and let jQuery handle the opacity when you have the mouse events trigger $('.lang1 span').fadeOut('fast');

다른 팁

why you don't use fadeToggle?

$('.lang1').hover(function() {
  $(this).find("span").fadeToggle("fast");
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top