5,006
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body style="background-color:yellow;">
<h3>透明背景的 PNG8 格式图片</h3>
<img src="http://www.w3help.org/zh-cn/causes/H/O/3/004/png8.png"/>
<h3>具有半透明过度背景的 PNG24 格式图片</h3>
<img src="http://www.w3help.org/zh-cn/causes/H/O/3/004/png24_alpha.png"/>
<h3>没有透明效果的 PNG24 格式图片</h3>
<img src="http://www.w3help.org/zh-cn/causes/H/O/3/004/png24_no_alpha.png"/>
</body>
</html>
效果比较图:<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript">
function fixpng24() {
var arVersion = navigator.appVersion.split("MSIE");
var version = parseFloat(arVersion[1]);
if ((version >= 5.5) && (document.body.filters)) {
for (var i = 0; i < document.images.length; i++) {
var img = document.images[i];
var imgName = img.src.toUpperCase();
if (imgName.substring(imgName.length - 3, imgName.length) == "PNG") {
var imgID = (img.id) ? "id='" + img.id + "' " : "";
var imgClass = (img.className) ? "class='" + img.className + "' " : "";
var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
var imgStyle = "display:inline-block;" + img.style.cssText;
if (img.align == "left") imgStyle = "float:left;" + imgStyle;
if (img.align == "right") imgStyle = "float:right;" + imgStyle;
if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
var strNewHTML = "<span " + imgID + imgClass + imgTitle
+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle
+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
img.outerHTML = strNewHTML;
i = i - 1;
}
}
}
}
window.onload=function(){
fixpng24();
}
</script>
</head>
<body style="background-color:yellow;">
<br/>透明背景的 PNG8 格式图片<br/>
<img src="http://www.w3help.org/zh-cn/causes/H/O/3/004/png8.png"/>
<br/>具有半透明过度背景的 PNG24 格式图片<br/>
<img src="http://www.w3help.org/zh-cn/causes/H/O/3/004/png24_alpha.png"/>
<br/>没有透明效果的 PNG24 格式图片<br/>
<img src="http://www.w3help.org/zh-cn/causes/H/O/3/004/png24_no_alpha.png"/>
</body>
</html>
关键是批量处理的那个函数 fixpng24()。