jquery隐藏元素在页面加载时加载1秒
我使用的是jquery滑入滑出,加载时(大约1秒)会显示在页面上,然后隐藏。我根本不想让它表现出来,我怎么能做到呢 我正在使用以下代码:jquery隐藏元素在页面加载时加载1秒,jquery,load,Jquery,Load,我使用的是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 cli
$(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;
});
});
只需通过css将#菜单默认隐藏即可:
#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()代码实际上不会运行 只需通过css默认隐藏菜单:
#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()代码实际上不会运行 您的事件只有在加载DOM后才会触发。最好用CSS隐藏它。将其放在页面顶部或样式表中
#menucategory {
display:none;
}
只有在加载DOM后,您的事件才会触发。最好用CSS隐藏它。将其放在页面顶部或样式表中
#menucategory {
display:none;
}
尝试将css样式元素置于#菜单分类显示:无尝试将css样式元素置于#菜单分类显示:无首先写入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');
});
})) 先写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');
});
})) 请把代码写在
jsfiddle.net上
我自己编写的-,我不知道你在问什么…啊,明白了。照@Razor Storm说的去做。请在jsfiddle.net
上写代码,我自己已经开始写了,我不知道你在问什么……啊,明白了。照@Razor Storm说的做。不需要$(“#菜单分类”)。隐藏()
如果您使用的是显示:none
CSSDon不需要$(“#菜单分类”).hide()代码>如果使用显示:无CSSdoes返回false代码>是必需的??我只包括返回语句,因为它们在原始postdoreturnfalse中代码>是必需的??我只包括返回语句,因为它们在原始帖子中