如何使PNG图片在IE浏览器实现透明效果
2010-09-05 15:28
686 查看
首先看我们的<img>标签代码:<img src="Example.png" border="0" alt="放大镜" />我们将利用IE中特有的特效来满足这个要求,这就是AlphaImageLoader Filter (http://msdn.microsoft.com/library/default.asp?url=/workshop/author/filter/reference/filters/alphaimageloader.asp) 如何做?将下面代码保存为correctPNG.js:
代码如下:
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; margin:6px; 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);
然后在你需要透明的网页中的<head>....</head>区加入:<script type="text/javascript" src="correctPNG.js"></script>
在<body>区加入多个与<img src="Example.png" border="0" alt="放大镜" />类似的PNG图片,试试看?
另一种方法:
代码如下:
<html>
<head>
<title>alpha image</title>
<style type="text/css">
.pngholder{
width:100px;
height:100px;
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://www.jb51.net/attachments/200510/03_124401_ie.png');
}
.pngalpha{
filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);
background:url(http://www.jb51.net/attachments/200510/03_124401_ie.png) no-repeat;
width:100px;
height:100px;
}
</style>
</head>
<body bgcolor="#3399ff#">
<!- And this is your code to implement the image ->
<div>透明</div>
<div class="pngholder"><div class="pngalpha"></div></div>
<div>不透明</div>
<img src="http://www.jb51.net/attachments/200510/03_124401_ie.png"/>
</body>
</html>
代码如下:
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; margin:6px; 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);
然后在你需要透明的网页中的<head>....</head>区加入:<script type="text/javascript" src="correctPNG.js"></script>
在<body>区加入多个与<img src="Example.png" border="0" alt="放大镜" />类似的PNG图片,试试看?
另一种方法:
代码如下:
<html>
<head>
<title>alpha image</title>
<style type="text/css">
.pngholder{
width:100px;
height:100px;
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://www.jb51.net/attachments/200510/03_124401_ie.png');
}
.pngalpha{
filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);
background:url(http://www.jb51.net/attachments/200510/03_124401_ie.png) no-repeat;
width:100px;
height:100px;
}
</style>
</head>
<body bgcolor="#3399ff#">
<!- And this is your code to implement the image ->
<div>透明</div>
<div class="pngholder"><div class="pngalpha"></div></div>
<div>不透明</div>
<img src="http://www.jb51.net/attachments/200510/03_124401_ie.png"/>
</body>
</html>
相关文章推荐
- 使PNG图片在IE浏览器实现透明效果代码
- 如何实现文字加透明背景显示在一张图片的底部的效果
- CSS实现PNG图片背景透明效果
- pngfix 实现Png图片透明效果
- IE浏览器PNG图片透明效果代码
- 如何使png图片在ie6里实现透明背景
- 在IE和VB中支持png图片透明效果的实现方法(vb源码打包)
- 在IE和VB中支持png图片透明效果的实现方法(vb源码打包)
- IE浏览器PNG图片透明效果代码
- IE浏览器PNG图片透明效果代码
- 如何将png图片转换成.9.png格式,textview实现跑马灯效果
- 实现 png-24 图片在 IE6 下透明的方法
- 网页设计之如何实现图片透明背景
- asp如何实现图片的动态翻动的效果
- ThinkPHP水印功能实现修复PNG透明水印并增加JPEG图片质量可调整
- 如何利用css使PNG图片透明
- [Javascript] 解决 IE6 中 png 图片背景不支持透明效果的问题
- 纯win32实现PNG图片透明窗体
- 实现TCHART+上面画透明图片飘动效果delphi