指定元素的隐藏|显示

一般像这样的双重状态我们都会提供3个api----show|hide|toggle

 

下面的api主要还是设置style.display来控制显示和隐藏。可以参考jQuery的做法,增加部分动画效果

 

1、先来显示吧。

 

 

/*
*show - show the element*
*@function*
*@param {string||HTMLElement} element*
*@return {HTMLElement}*
*TODO--later i will add speed to this api just like jquery*
http://code.jquery.com/jquery-1.4.js
*/
ZYC.dom.show = function(element){
    element = ZYC.dom.g(element);
    element.style.display = "";
    return element;
};
 

 2、再隐藏起来

 

 

/*
*hide - hide the element*
*@function*
*@param {string||HTMLElement} element*
*@return {HTMLElement}*
*TODO--later i will add speed to this api just like jquery*
http://code.jquery.com/jquery-1.4.js
*/
ZYC.dom.hide = function(element){
    element = ZYC.dom.g(element);
    element.style.display = "none";
    return element;
};

 

3、可切换当前显示和隐藏的

 

 

/*
*toggle - change the show/hide of the element*
*@function*
*@param {string||HTMLElement} element*
*@return {HTMLElement}*
*TODO--later i will add speed to this api just like jquery*
http://code.jquery.com/jquery-1.4.js
*/
ZYC.dom.toggle = function(element){
        element = ZYC.dom.g(element);
	element.style.display = element.style.display=="none" ?"" : "none";
};

你可能感兴趣的:(hide,toggle,show)