jQuery slide方法的原理

下面先貼一段源碼
function genFx( type, includeWidth ) {
	var which,
		attrs = { height: type },
		i = 0;

	// if we include width, step value is 1 to do all cssExpand values,
	// if we don't include width, step value is 2 to skip over Left and Right
	includeWidth = includeWidth ? 1 : 0;
	for ( ; i < 4 ; i += 2 - includeWidth ) {
		which = cssExpand[ i ];
		attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
	}

	if ( includeWidth ) {
		attrs.opacity = attrs.width = type;
	}

	return attrs;
}

上面的代碼爲jQuery源碼,但是看不懂。之後我在執行slide方法時輸出操作元素的各個屬性

alert($("#1").next().css('display'));
$("#1").nextUntil('#2').slideToggle(1);


輸出的各個值:visibility:visible;height:24px;這兩者無論隱藏還是顯示都不改變。

display在隱藏時爲none           顯示時爲table-row(我隱藏的是表格)

所以小夥伴們,以後在使用slide方法可以用判斷display的值來確定元素是隱藏狀態還是顯示狀態

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章