`
hrsvici412
  • 浏览: 75440 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

精通JavaScript源码3

阅读更多

设置元素的隐藏或者可见:

// A function for hiding (using display) an element
function hide( elem ) {
    // Find out what it’s current display state is
    var curDisplay = getStyle( elem, ‘display’ );
    //  Remember its display state for later
    if ( curDisplay != ‘none’ )
        elem.$oldDisplay = curDisplay;
    // Set the display to none (hiding the element)
    elem.style.display = ‘none’;
}
// A function for showing (using display) an element
function show( elem ) {
    // Set the display property back to what it use to be, or use
    // ‘block’, if no previous display had been saved
    elem.style.display = elem.$oldDisplay || ‘block’;
}

   设置元素的透明度:

// Set an opacity level for an element
// (where level is a number 0-100)
function setOpacity( elem, level ) {
    // If filters exist, then this is IE, so set the Alpha filter
    if ( elem.filters )
        elem.filters.alpha.opacity = level;

    // Otherwise use the W3C opacity property
    else
        elem.style.opacity = level / 100;
}
 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics