六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 114|回复: 0

ie6下实现png透明

[复制链接]

升级  24%

22

主题

22

主题

22

主题

秀才

Rank: 2

积分
86
 楼主| 发表于 2013-1-29 07:31:41 | 显示全部楼层 |阅读模式
update:最近发现一个更好的解决方案,使用VML替换AlphaImageLoader,可以解决被替换元素hover状态不起作用的问题。详见:http://www.dillerdesign.com/experiment/DD_belatedPNG/。我使用VML方式做的页面:http://fang.kuwo.cn/p/Radio
 
// Universal transparent-PNG enabler for MSIE/Win 5.5+// http://dsandler.org// From original code: http://www.youngpup.net/?request=/snippets/sleight.xml// and background-image code: http://www.allinthehead.com/retro/69// also://  * use sizingMethod=crop to avoid scaling PNGs (who would do such a thing?)//  * only do this once, to make it compatible with CSS rolloversif (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {window.attachEvent("onload", enableAlphaImages);}function enableAlphaImages(){var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);if (itsAllGood) {for (var i=0; i<document.all.length; i++){var obj = document.all;var bg = obj.currentStyle.backgroundImage;var img = document.images;if (bg && bg.match(/\.png/i) != null) {var img = bg.substring(5,bg.length-2);var offset = obj.style["background-position"];obj.style.filter ="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img+"', sizingMethod='crop')";obj.style.backgroundImage = "url('/images/spacer.gif')";obj.style["background-position"] = offset; // reapply} else if (img && img.src.match(/\.png$/i) != null) {var src = img.src;img.style.width = img.width + "px";img.style.height = img.height + "px";img.style.filter ="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"', sizingMethod='crop')"img.src = "/images/spacer.gif";}}}}注意,需要将png图片设置为元素的背景图片,并且添加一个图片“spacer.gif”。
示例见:http://blog.gulu77.com/demo/200809/test_PNGTransparncyinIE/
 
转自:http://blog.gulu77.com/?p=147
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表