javascript - 隐藏()与隐藏 ("slow")

标签 javascript jquery html

我需要隐藏一个 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 的箭头。但是,如果我尝试使用 hide("slow"),则当我的 div 关闭时,divTitle 和 divArrow 不会出现。使用 hide(1000) 同样的问题。

有和没有“慢”参数的隐藏之间有区别吗?

谢谢, 安德里亚

最佳答案

来自官方网站

The matched elements will be hidden immediately, with no animation. This is roughly equivalent to calling .css('display', 'none'), except that the value of the display property is saved in jQuery's data cache so that display can later be restored to its initial value. If an element has a display value of inline, then is hidden and shown, it will once again be displayed inline.

When a duration is provided, .hide() becomes an animation method. The .hide() method animates the width, height, and opacity of the matched elements simultaneously. When these properties reach 0, the display style property is set to none to ensure that the element no longer affects the layout of the page.

因此,如果立即使用 hide,它会立即隐藏而不产生动画 - 例如,噗。

如果随着时间的推移使用它,它就会变成动画,因此它会随着时间的推移而消失。

对于你的问题,没有相应的html代码很难判断。

关于javascript - 隐藏()与隐藏 ("slow"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13589528/

相关文章:

javascript - Angular 如何处理具有多个指令的元素

javascript - userServic不会将数据传递到后端: Cannot read property 'protocol' of undefined - AngularJS

javascript - Jquery Mobile 1.4.5 设备中的虚拟键盘隐藏页面底部的表单输入

javascript - jQuery在随机时间生成随机数

javascript - 将 ngClass 应用于声明 ngRepeat 的元素

javascript - 为了更好地进行单元测试,静态类型 javascript 的示例是什么?

javascript - 与 ng-attr-myCustomAttribute 匹配的自定义属性指令

javascript - 去匿名化 jQuery 中的匿名函数

javascript - HTML/CSS - 修复了带有可滚动内容的页面边框

javascript - 动画div的高度