jquery api

作者: 蘑菇酱960903 | 来源:发表于2018-04-11 13:14 被阅读0次
  • toggle
    .toggle(duration,easing, function)
    duration:持续时间
    easing:缓动函数(linear swing)
    function:动画完成时执行的函数

一、.toggle();没有参数
改变css的display属性,匹配元素的display = none将被立即显示 display = block | inline-block | inline将被隐藏,没有动画
二、分析
当传进去的参数为true,则display为none的将显示,当为false,将隐藏

toggle: function( state ) {
        if ( typeof state === "boolean" ) {
            return state ? this.show() : this.hide();
        }

        return this.each( function() {
            if ( isHiddenWithinTree( this ) ) {
                jQuery( this ).show();
            } else {
                jQuery( this ).hide();
            }
        } );
    }
//判断元素是否是隐藏的
var isHiddenWithinTree = function( elem, el ) {

        // isHiddenWithinTree might be called from jQuery#filter function;
        // in that case, element will be second argument
        elem = el || elem;

        // Inline style trumps all
        return elem.style.display === "none" ||
            elem.style.display === "" &&

            // Otherwise, check computed style
            // Support: Firefox <=43 - 45
            // Disconnected elements can have computed display: none, so first confirm that elem is
            // in the document.
            jQuery.contains( elem.ownerDocument, elem ) &&

            jQuery.css( elem, "display" ) === "none";
    };

相关文章

网友评论

    本文标题:jquery api

    本文链接:https://www.haomeiwen.com/subject/gbrahftx.html