悬停,DIV淡入但不淡出 [英] Hover, DIV fades in but not out

查看:71
本文介绍了悬停,DIV淡入但不淡出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$(document).ready(function(){
    $(".thumbnail").hover(
        function(){
            $(".overthumb").fadeTo(1000,1).show();
        },
        function(){
            $(".overthumb").fadeTo(1000,0).hide();
        }
    );
});

http://jsfiddle.net/AndyMP/qCa7a/2/

上面的代码使DIV淡入,但由于某种原因不会淡出.

The code above makes a DIV fade in, but for some reason won't fade out.

也许FadeOut不是这样做的最好方法吗?

Maybe FadeOut isn't the best way of doing this?

推荐答案

正如丹尼尔所说,您无需致电hide(),但是您也无需致电show().

As Daniel has said, you don't need to call hide(), however you also don't need to call show().

旁注-您正在使用功能fadeTo(),该功能主要用于将元素淡化为特定的不透明度值(即4%).看到您只是将元素从0%-100%淡入,反之亦然,则可以分别使用以下功能:fadeIn()& fadeOut().

A side note - you're using the function fadeTo() which is mainly used to fade an element to a specific opacity value (i.e. 4%). Seeing as you're just fading the element from 0% - 100% and vice versa, you can use these functions respectively: fadeIn() & fadeOut().

以下是使用上述功能的示例:

Here's an example of using the above functions:

    // Bind the event to the required element
    $('#elementid').hover(
        function(){

            // Call the function on a specific element to fade in
            $('.overthumb').fadeIn(1000);

        },
        function(){

            // Call the opposite function on the same element to fade out
            $(".overthumb").fadeOut(1000);
        }
    );

以下是指向jQueryAPI文档的以下功能的链接: fadeIn()& fadeOut()

Here are the link to the jQueryAPI document for the following functions: fadeIn() & fadeOut()

这篇关于悬停,DIV淡入但不淡出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆