我需要隐藏一个div,使用下面的代码可以很好地工作:
var idObj = $(this).attr('key');
var valH = $(this).attr('hideval');
var valS = $(this).attr('showval');
if ($('div[name='+idObj+']').attr('isdisplay') == 'no') {
$('div[name='+idObj+']').children().show("slow");
$('div[name='+idObj+']').attr('isdisplay','yes');
var divTitle = $('div[name='+idObj+']').children().first();
var divArrow = $(this).children().first();
//.attr('src',prefixImg+valH);
//divTitle.show();
//divArrow.show();
$(this).children().first().attr('src',prefixImg+valH);
} else {
var divTitle = $('div[name='+idObj+']').children().first();
var divArrow = $('div[name='+idObj+']').children().last();
//.attr('src',prefixImg+valS);
$('div[name='+idObj+']').children().hide();
$('div[name='+idObj+']').attr('isdisplay','no');
divTitle.show();
divArrow.show();
$(this).children().first().attr('src',prefixImg+valS);
}我的div是隐藏的,显示了重新打开div的标题和箭头。但是如果我尝试使用隐藏(“慢”),当我的div关闭时,divTitle和divArrow就不会出现。使用hide(1000)也有同样的问题。
使用"slow“参数和不使用”slow“参数的hide有区别吗?
谢谢,安德里亚
发布于 2012-11-28 01:24:51
$(element).hide()会立即隐藏一个元素,$(element).hide('slow')会以动画方式(缓慢地)显示该元素的消失。
看起来(虽然我不确定)你想要在动画结束后做一些事情。在这种情况下,执行如下操作:
var that = this; // here to preserve scope for the block below
$('div[name='+idObj+']').children().hide('slow', function() {
// This stuff happens after the hide animation is done.
$('div[name='+idObj+']').attr('isdisplay','no');
divTitle.show();
divArrow.show();
$(that).children().first().attr('src',prefixImg+valS); // <= note "that" instead of "this"
});发布于 2012-11-28 01:21:28
来自官方网站
匹配的元素将立即隐藏,没有动画。这大致等同于调用.css(' display ','none'),只不过display属性的值保存在jQuery的数据缓存中,以便稍后可以将display恢复为其初始值。如果元素的显示值为inline,则隐藏并显示该元素,它将再次以内联方式显示。
当提供持续时间时,.hide()成为一个动画方法。.hide()方法同时对匹配元素的宽度、高度和不透明度进行动画处理。当这些属性达到0时,display style属性将设置为none,以确保元素不再影响页面布局。
因此,如果没有延迟地使用hide,它会立即隐藏起来,而不会产生动画效果。
如果它与时间一起使用,它会变成动画,因此它会随着时间的推移而消失。
对于你的问题,没有相应的html代码是很难判断的。
发布于 2012-11-28 01:21:20
根据jQuery文档
可以提供字符串‘
’和'slow‘来分别指示200毫秒和600毫秒的持续时间。
还可以向它提供以毫秒为单位的持续时间。
https://stackoverflow.com/questions/13589528
复制相似问题