2011-03-01 137 views
1

我正在使用jQuery幻燈片出現在頁面上出現在頁面上時加載(約1秒),然後被隱藏。我不想讓它顯示出來,我該怎麼做?jquery隱藏元素加載頁面加載1秒

我使用這個代碼:

$(document).ready(function() { 
// hides the slickbox as soon as the DOM is ready 
// (a little sooner than page load) 
    $('#menucategory').hide(); 
// shows the slickbox on clicking the noted link 
    $('img.menu_class').click(function() { 
$('#menucategory').show('slow'); 
return false; 
    }); 
// hides the slickbox on clicking the noted link 
    $('a#hidecategory').click(function() { 
$('#menucategory').hide('slow'); 
return false; 
    }); 

}); 
+0

請將代碼寫在'jsfiddle.net'上 – diEcho 2011-03-01 10:02:51

+0

我已經自行編寫代碼 - [http://jsfiddle.net/xbHbP/](http://jsfiddle.net/xbHbP/1 ),我實際上不知道你在問什麼... – Alex 2011-03-01 10:05:07

+0

ahhhh做到了。 @Razor Storm說了些什麼? – Alex 2011-03-01 10:05:42

回答

0

你的事件只會在DOM加載後觸發。最好只用CSS來隱藏它。你應該在你的頁面的頂部或在樣式表

#menucategory { 
    display:none; 
} 
1

只是要通過CSS默認是隱藏的#menucateogry:

#menucategory 
{ 
    display:none; 
} 

然後,所有你需要的是以下幾點:

$(document).ready(function() { 

    $('img.menu_class').click(function() { 
     $('#menucategory').show('slow'); 
     return false; 
    }); 

    $('a#hidecategory').click(function() { 
     $('#menucategory').hide('slow'); 
     return false; 
    }); 
}); 

編輯:原因是,因爲你正在做$(document).ready(),你的hide()代碼將不會真正運行,直到圖像完成加載。

+0

'返回false;'是必要的? – diEcho 2011-03-01 10:25:45

+0

我只包含返回語句,因爲它們在原始文章中 – 2011-03-01 10:48:30

0

嘗試把CSS樣式元素#menucategory顯示:無

0

第一次寫CSS

#menucategory 
{ 
display:none; 
} 

然後下面寫代碼

jQuery(document).ready(function() { 
    jQuery('img.menu_class').click(function() { 
     jQuery('#menucategory').show('slow'); 
    }); 
    jQuery('a#hidecategory').click(function() { 
     jQuery('#menucategory').hide('slow'); 
    }); 

});

+0

不需要'$('#menucategory')。hide();'如果您使用的是display:none'CSS – Alex 2011-03-01 10:06:42

+0

@Alex yes ur對 – diEcho 2011-03-01 10:07:15