网络营销服务:
常见问题:
营销博客:
联系我们:
- 电话:020-82304353
- Q Q:920903195 961131181
- 传真:020-82304401
- 邮箱:services@henzong.net
- 地址:广州市中山大道中268号天河广场天威阁17D
网页设计:在IE浏览器中正确显示PNG透明图片
作者:佚名 来源:天极网 更新时间:2008-4-15
png图片有很好的品质。阴影效果也不会有杂边,很流畅。如果插入网页的话可以给网站内容增色不少!更重要的是在不增加图片容量大小的情况下提高了页面的图片的质量。对于有复杂背景,如:在有颜色过度背景上插入不规则边框的图片带来极大很便利!
但目前IE中对于插入的透明背景的.png的图片是不能正常显示的。IE会自动给".png"格式的图片加个灰色背景。
解决这个的方法是增加javascript。具体方法如下:
把下面的代码放在head区就可以解决问题了。
以下是引用片段:
<script language="javascript">
function correctPNG()
{
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.attachEvent("onload", correctPNG);
</script>
也可以把这段代码单独加在一张图片上:
以下是引用片段:
<span
style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’male.png’,sizingMethod=’scale’);"></span>
但目前IE中对于插入的透明背景的.png的图片是不能正常显示的。IE会自动给".png"格式的图片加个灰色背景。
解决这个的方法是增加javascript。具体方法如下:
把下面的代码放在head区就可以解决问题了。
以下是引用片段:
<script language="javascript">
function correctPNG()
{
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.attachEvent("onload", correctPNG);
</script>
也可以把这段代码单独加在一张图片上:
以下是引用片段:
<span
style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’male.png’,sizingMethod=’scale’);"></span>
本网转载作品均注明出处,内容仅供参阅,与本站的立场无关。如转载作品侵犯您的权益,并非出于本网故意,在接到相关权利人通知后会加以更正。
