IE6实现PNG图片透明JavaScript代码
因为IE6一下的版本是不支持PNG格式的图片的,想要在IE6实现透明图片,需要另外想办法有个简单的办法,用PS把图片转换成GIF格式,但是这样做的后果是,图片锯齿很严重
另外就是需要JS代码来实现了,我给你一段代码,放到HEAD里面就行了
PNG图片透明代码:
<script>
function correctPNG(){
for(var i=0; i<document.images.length; i++) {
var img = document.images
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='image');\"></span>"
img.outerHTML = strNewHTML
i = i-1
}
}
}
window.attachEvent("onload", correctPNG);
</script>
沙发……偶也 我来看看我有多少钱..... 地板支持下
哇咔 菜鸟一个…看不懂… 确实,看不懂,哈哈
页:
[1]