文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>PNG在IE6下透明显示

PNG在IE6下透明显示

时间:2010-06-28  来源:2008liangyou

#title{behavior: url("./im/iepngfix.htc")} IE6背景透明
2010年03月12日 星期五 13:53
css文件里
#title{behavior: url("./im/iepngfix.htc")}

iepngfix.htc文件
<public:component>
<script type="text/javascript">

// IE5.5+ PNG Alpha Fix v2.0 Alpha
// (c) 2004-2009 Angus Turnbull http://www.twinhelix.com

// This is licensed under the GNU LGPL, version 2.1 or later.
// For details, see: http://creativecommons.org/licenses/LGPL/2.1/

var IEPNGFix = window.IEPNGFix || {};
IEPNGFix.data = IEPNGFix.data || {};


// CONFIG: blankImg is the path to blank.gif, *relative to the HTML document*.
// Try either:
// * An absolute path like:  '/images/blank.gif'
// * A path relative to this HTC file like:  thisFolder + 'blank.gif'
var thisFolder = document.URL.replace(/(\\|\/)[^\\\/]*$/, '/');
IEPNGFix.blankImg = thisFolder + 'blank.gif';


IEPNGFix.fix = function(elm, src, t) {
// Applies an image 'src' to an element 'elm' using the DirectX filter.
// If 'src' is null, filter is disabled.
// Disables the 'hook' to prevent infinite recursion on setting BG/src.
// 't' = type, where background tile = 0, background = 1, IMG SRC = 2.

var h = this.hook.enabled;
this.hook.enabled = 0;

var f = 'DXImageTransform.Microsoft.AlphaImageLoader';
src = (src || '').replace(/\(/g, '%28').replace(/\)/g, '%29');

if (
src && !(/IMG|INPUT/.test(elm.nodeName) && (t != 2)) &&
elm.currentStyle.width == 'auto' && elm.currentStyle.height == 'auto'
) {
if (elm.offsetWidth) {
elm.style.width = elm.offsetWidth + 'px';
}
if (elm.clientHeight) {
elm.style.height = elm.clientHeight + 'px';
}
if (elm.currentStyle.display == 'inline') {
elm.style.display = 'inline-block';
}
}
if (t == 1) {
elm.style.backgroundImage = 'url("' + this.blankImg + '")';
}
if (t == 2||t == 3) {
elm.src = this.blankImg;
}

if (elm.filters[f]) {
elm.filters[f].enabled = src ? true : false;
if (src) {
elm.filters[f].src = src;
}
} else if (src) {
elm.style.filter = 'progid:' + f + '(src="' + src +
'",sizingMethod="' + (t == 2 ? 'scale' : (t == 3 ? 'image' : 'crop')) + '")';
}

this.hook.enabled = h;
};


IEPNGFix.process = function(elm, init) {
// Checks the onpropertychange event (on first 'init' run, a fake event)
// and calls the filter-applying-functions.

if (
!/MSIE (5\.5|6)/.test(navigator.userAgent) ||
typeof elm.filters == 'unknown'
) {
return;
}
if (!this.data[elm.uniqueID]) {
this.data[elm.uniqueID] = {
className: ''
};
}
var data = this.data[elm.uniqueID],
evt = init ? { propertyName: 'src,backgroundImage' } : event,
isSrc = /src/.test(evt.propertyName),
isBg = /backgroundImage/.test(evt.propertyName),
isClass = !init && ((elm.className != data.className) &&
(elm.className || data.className));
if (!(isSrc || isBg || isClass)) {
return;
}
data.className = elm.className;
var blank = this.blankImg.match(/([^\/]+)$/)[1],
eS = elm.style,
eCS = elm.currentStyle;

// Required for Whatever:hover - erase set BG if className changes.
if (
isClass && (eS.backgroundImage.indexOf('url(') == -1 ||
eS.backgroundImage.indexOf(blank) > -1)
) {
return setTimeout(function() {
eS.backgroundImage = '';
}, 0);
}

// Foregrounds.
if (isSrc && elm.src && { IMG: 1, INPUT: 1 }[elm.nodeName]) {
if ((/\.png/i).test(elm.src)) {
if (!elm.oSrc) {
// MM rollover compat
elm.oSrc = elm.src;
}
this.fix(elm, elm.src, 2);
} else if (elm.src.indexOf(blank) == -1) {
this.fix(elm, '');
}
}
// Backgrounds.
var bgSrc = eCS.backgroundImage || eS.backgroundImage;
if ((bgSrc + elm.src).indexOf(blank) == -1) {
var bgPNG = bgSrc.match(/url[("']+(.*\.png[^\)"']*)[\)"']/i);
if (bgPNG) {
this.fix(this.bgPosition(elm), bgPNG[1],elm.currentStyle.backgroundRepeat=='no-repeat'?3:2);
} else {
this.fix(elm, '');
}
}

if (init) {
this.hook.enabled = 1;
elm.attachEvent('onpropertychange', this.hook);
}
};
IEPNGFix.bgPosition = function(elm){
if(!elm.obj){
elm.obj=document.createElement('div');
}
var obj=elm.obj,eCS=elm.currentStyle;
if(elm.htc &&elm.htc.apply){elm.htc.apply(elm,[obj]);
}
var cssT="position:absolute;width:100%;height:100%;Z-INDEX:"+(eCS.zIndex-1)+";";
if(/center/i.test(eCS.backgroundPositionX)){cssT+="left:45%;";
}else if(/left/i.test(eCS.backgroundPositionX)){cssT+="left:0px;";
}else if(/right/i.test(eCS.backgroundPositionX)){cssT+="right:0px;";
}else cssT+="left:"+eCS.backgroundPositionX+";";
if(/center/i.test(eCS.backgroundPositionY)){cssT+="top:45%;";
}else if(/left/i.test(eCS.backgroundPositionY)){cssT+="top:0px;";
}else if(/right/i.test(eCS.backgroundPositionY)){cssT+="bottom:0px;";
}else cssT+="top:"+eCS.backgroundPositionY+";";
obj.style.cssText=cssT;
elm.appendChild(obj);
elm.style.backgroundImage="none";
elm.style.overflow="hidden";
return obj;
};


IEPNGFix.hook = function() {
if (IEPNGFix.hook.enabled) {
if(!this.nodeType)return;
IEPNGFix.process(element, 0);
}
};

IEPNGFix.process(element, 1);

</script>
</public:component>
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载