加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

javascript – hide()vs hide(“slow”)

发布时间:2020-12-14 23:04:05 所属栏目:资源 来源:网络整理
导读:我需要隐藏一个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(

我需要隐藏一个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)的相同问题.

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

谢谢,
安德里亚

最佳答案
$(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"

});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读