悬停,DIV淡入但没有出局

时间:2012-02-02 16:43:17

标签: jquery

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

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

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

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

2 个答案:

答案 0 :(得分:2)

请勿致电hide

http://jsfiddle.net/qCa7a/3/

答案 1 :(得分:2)

正如丹尼尔所说,你不需要致电hide(),但你也不需要致电show()

附注 - 你正在使用函数fadeTo(),它主要用于将元素淡化为特定的不透明度值(即4%)。看到你只是将元素从0% - 100%淡化,反之亦然,你可以分别使用这些函数:fadeIn()& fadeOut()

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

    // 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()

相关问题