簡體   English   中英

當我增加速度時,jQuery效果不起作用

[英]jQuery effects don't work when I add a speed

我對jQuery(和javascript而言)還很陌生,所以這可能只是我正在做的愚蠢的事情,但這確實讓我很煩!

我要做的就是增加jQuery的隱藏和顯示功能的速度。 我使用的代碼是:

for (var i in clouds) {
    $(clouds[i]).click(function() {
    $(this).hide();
    });
}

在單擊時隱藏雲,以及

function fadeLogo(state) { 
    var element=document.getElementById('logo');

    if (state=='home') {
        element.hide;
        element.src='images/home.png';
        element.show;
    }

    else {
        element.hide;
        element.src='images/webNameLogo.png';
        element.show;
    }
}

隱藏圖像,進行更改然后再次顯示。 這叫做

onMouseOver=fadeLogo('home') onMouseOut=fadeLogo('logo')

這可以正常工作,但會立即發生。 每當我嘗試以“慢”,“快”或毫秒為單位添加速度時,它都將不起作用,它們只會保持其原始狀態。 甚至沒有速度就添加hide()都會在Safari的錯誤控制台中引發錯誤:

TypeError:表達式'element.hide'的結果[未定義]不是函數。

沒有關於雲的錯誤報告,他們只是坐在那里什么也不做!

希望有人能幫忙!

謝謝

編輯:

現在,有此用於圖像更改:

$(function() { //This function fades the logo to the home button on mouseover

    $('.logo').hover(function() {
        $(this).fadeOut(
            'slow',
            function () {
                $(this).attr ('src','images/home.png').fadeIn('slow');
            });
    }, function() {
        $(this).fadeOut(
            'slow',
            function () {
                $(this).attr('src','images/webNameLogo.png').fadeIn('slow');
            });
    });
});

這會使圖像淡出,沒有問題,但在兩個圖像之間不會改變...糟糕,應該是#logo。 現在讓那個正在工作,到討厭的雲層上。

hide()方法的用法如下:

for (var i in clouds) {
    $(clouds[i]).click(function() {
    $(this).hide( 'slow' ); // or you can pass the milliseconds
    });
}

至於圖像隱藏,您應該執行以下操作:

$( 'selector for your image' ).hide (
    'slow',
    function () {
        $( this ).attr ( 'src', 'images/other.png' ).show ( 'slow' );
    }
);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM