在head里引入png.js文件

<!--[if lte IE 6]> 
<script type="text/javascript" src="js/PNG.js"></script> 
<script> 
PNG.fix('*'); 
</script> 
<![endif]-->

png.js文件内容如下:、

/**
* PNG: Adds IE6 support: PNG images for CSS background-image and HTML <IMG/>.
* Author: Drew Diller
* Email: drew.diller@gmail.com
* URL: http://www.dillerdesign.com/experiment/PNG/
* Version: 0.0.7a
* Licensed under the MIT License: http://dillerdesign.com/experiment/PNG/#license
*
* Example usage:
* PNG.fix('.png_bg'); // argument is a CSS selector
* PNG.fixPng( someNode ); // argument is an HTMLDomElement
**//*
PLEASE READ:
Absolutely everything in this script is SILLY.  I know this.  IE's rendering of certain pixels doesn't make sense, so neither does this code!
*/var PNG = {ns: 'PNG',imgSize: {},createVmlNameSpace: function() { /* enable VML */if (document.namespaces && !document.namespaces[this.ns]) {document.namespaces.add(this.ns, 'urn:schemas-microsoft-com:vml');}if (window.attachEvent) {window.attachEvent('onbeforeunload', function() {PNG = null;});}},createVmlStyleSheet: function() { /* style VML, enable behaviors *//*Just in case lots of other developers have addedlots of other stylesheets using document.createStyleSheetand hit the 31-limit mark, let's not use that method!further reading: http://msdn.microsoft.com/en-us/library/ms531194(VS.85).aspx*/var style = document.createElement('style');document.documentElement.firstChild.insertBefore(style, document.documentElement.firstChild.firstChild);var styleSheet = style.styleSheet;styleSheet.addRule(this.ns + '\\:*', '{behavior:url(#default#VML)}');styleSheet.addRule(this.ns + '\\:shape', 'position:absolute;');styleSheet.addRule('img.' + this.ns + '_sizeFinder', 'behavior:none; border:none; position:absolute; z-index:-1; top:-10000px; visibility:hidden;'); /* large negative top value for avoiding vertical scrollbars for large images, suggested by James O'Brien, http://www.thanatopsic.org/hendrik/ */this.styleSheet = styleSheet;},readPropertyChange: function() {var el = event.srcElement;if (event.propertyName.search('background') != -1 || event.propertyName.search('border') != -1) {PNG.applyVML(el);}if (event.propertyName == 'style.display') {var display = (el.currentStyle.display == 'none') ? 'none' : 'block';for (var v in el.vml) {el.vml[v].shape.style.display = display;}}if (event.propertyName.search('filter') != -1) {PNG.vmlOpacity(el);}},vmlOpacity: function(el) {if (el.currentStyle.filter.search('lpha') != -1) {var trans = el.currentStyle.filter;trans = parseInt(trans.substring(trans.lastIndexOf('=')+1, trans.lastIndexOf(')')), 10)/100;el.vml.color.shape.style.filter = el.currentStyle.filter; /* complete guesswork */el.vml.image.fill.opacity = trans; /* complete guesswork */}},handlePseudoHover: function(el) {setTimeout(function() { /* wouldn't work as intended without setTimeout */PNG.applyVML(el);}, 1);},/*** This is the method to use in a document.* @param {String} selector - REQUIRED - a CSS selector, such as '#doc .container'**/fix: function(selector) {var selectors = selector.split(','); /* multiple selectors supported, no need for multiple calls to this anymore */for (var i=0; i<selectors.length; i++) {this.styleSheet.addRule(selectors[i], 'behavior:expression(PNG.fixPng(this))'); /* seems to execute the function without adding it to the stylesheet - interesting... */}},applyVML: function(el) {el.runtimeStyle.cssText = '';this.vmlFill(el);this.vmlOffsets(el);this.vmlOpacity(el);if (el.isImg) {this.copyImageBorders(el);}},attachHandlers: function(el) {var self = this;var handlers = {resize: 'vmlOffsets', move: 'vmlOffsets'};if (el.nodeName == 'A') {var moreForAs = {mouseleave: 'handlePseudoHover', mouseenter: 'handlePseudoHover', focus: 'handlePseudoHover', blur: 'handlePseudoHover'};for (var a in moreForAs) {handlers[a] = moreForAs[a];}}for (var h in handlers) {el.attachEvent('on' + h, function() {self[handlers[h]](el);});}el.attachEvent('onpropertychange', this.readPropertyChange);},giveLayout: function(el) {el.style.zoom = 1;if (el.currentStyle.position == 'static') {el.style.position = 'relative';}},copyImageBorders: function(el) {var styles = {'borderStyle':true, 'borderWidth':true, 'borderColor':true};for (var s in styles) {el.vml.color.shape.style[s] = el.currentStyle[s];}},vmlFill: function(el) {if (!el.currentStyle) {return;} else {var elStyle = el.currentStyle;}for (var v in el.vml) {el.vml[v].shape.style.zIndex = elStyle.zIndex;}el.runtimeStyle.backgroundColor = '';el.runtimeStyle.backgroundImage = '';var noColor = (elStyle.backgroundColor == 'transparent');var noImg = true;if (elStyle.backgroundImage != 'none' || el.isImg) {if (!el.isImg) {el.vmlBg = elStyle.backgroundImage;el.vmlBg = el.vmlBg.substr(5, el.vmlBg.lastIndexOf('")')-5);}else {el.vmlBg = el.src;}var lib = this;if (!lib.imgSize[el.vmlBg]) { /* determine size of loaded image */var img = document.createElement('img');lib.imgSize[el.vmlBg] = img;img.className = lib.ns + '_sizeFinder';img.runtimeStyle.cssText = 'behavior:none; position:absolute; left:-10000px; top:-10000px; border:none;'; /* make sure to set behavior to none to prevent accidental matching of the helper elements! */img.attachEvent('onload', function() {this.width = this.offsetWidth; /* weird cache-busting requirement! */this.height = this.offsetHeight;lib.vmlOffsets(el);});img.src = el.vmlBg;img.removeAttribute('width');img.removeAttribute('height');document.body.insertBefore(img, document.body.firstChild);}el.vml.image.fill.src = el.vmlBg;noImg = false;}el.vml.image.fill.on = !noImg;el.vml.image.fill.color = 'none';el.vml.color.shape.style.backgroundColor = elStyle.backgroundColor;el.runtimeStyle.backgroundImage = 'none';el.runtimeStyle.backgroundColor = 'transparent';},/* IE can't figure out what do when the offsetLeft and the clientLeft add up to 1, and the VML ends up getting fuzzy... so we have to push/enlarge things by 1 pixel and then clip off the excess */vmlOffsets: function(el) {var thisStyle = el.currentStyle;var size = {'W':el.clientWidth+1, 'H':el.clientHeight+1, 'w':this.imgSize[el.vmlBg].width, 'h':this.imgSize[el.vmlBg].height, 'L':el.offsetLeft, 'T':el.offsetTop, 'bLW':el.clientLeft, 'bTW':el.clientTop};var fudge = (size.L + size.bLW == 1) ? 1 : 0;/* vml shape, left, top, width, height, origin */var makeVisible = function(vml, l, t, w, h, o) {vml.coordsize = w+','+h;vml.coordorigin = o+','+o;vml.path = 'm0,0l'+w+',0l'+w+','+h+'l0,'+h+' xe';vml.style.width = w + 'px';vml.style.height = h + 'px';vml.style.left = l + 'px';vml.style.top = t + 'px';};makeVisible(el.vml.color.shape, (size.L + (el.isImg ? 0 : size.bLW)), (size.T + (el.isImg ? 0 : size.bTW)), (size.W-1), (size.H-1), 0);makeVisible(el.vml.image.shape, (size.L + size.bLW), (size.T + size.bTW), (size.W), (size.H), 1);var bg = {'X':0, 'Y':0};var figurePercentage = function(axis, position) {var fraction = true;switch(position) {case 'left':case 'top':bg[axis] = 0;break;case 'center':bg[axis] = .5;break;case 'right':case 'bottom':bg[axis] = 1;break;default:if (position.search('%') != -1) {bg[axis] = parseInt(position)*.01;}else {fraction = false;}}var horz = (axis == 'X');bg[axis] = Math.ceil(fraction ? ( (size[horz?'W': 'H'] * bg[axis]) - (size[horz?'w': 'h'] * bg[axis]) ) : parseInt(position));if (bg[axis] == 0) {bg[axis]++;}};for (var b in bg) {figurePercentage(b, thisStyle['backgroundPosition'+b]);}el.vml.image.fill.position = (bg.X/size.W) + ',' + (bg.Y/size.H);var bgR = thisStyle.backgroundRepeat;var dC = {'T':1, 'R':size.W+fudge, 'B':size.H, 'L':1+fudge}; /* these are defaults for repeat of any kind */var altC = { 'X': {'b1': 'L', 'b2': 'R', 'd': 'W'}, 'Y': {'b1': 'T', 'b2': 'B', 'd': 'H'} };if (bgR != 'repeat') {var c = {'T':(bg.Y), 'R':(bg.X+size.w), 'B':(bg.Y+size.h), 'L':(bg.X)}; /* these are defaults for no-repeat - clips down to the image location */if (bgR.search('repeat-') != -1) { /* now let's revert to dC for repeat-x or repeat-y */var v = bgR.split('repeat-')[1].toUpperCase();c[altC[v].b1] = 1;c[altC[v].b2] = size[altC[v].d];}if (c.B > size.H) {c.B = size.H;}el.vml.image.shape.style.clip = 'rect('+c.T+'px '+(c.R+fudge)+'px '+c.B+'px '+(c.L+fudge)+'px)';}else {el.vml.image.shape.style.clip = 'rect('+dC.T+'px '+dC.R+'px '+dC.B+'px '+dC.L+'px)';}},fixPng: function(el) {el.style.behavior = 'none';if (el.nodeName == 'BODY' || el.nodeName == 'TD' || el.nodeName == 'TR') { /* elements not supported yet */return;}el.isImg = false;if (el.nodeName == 'IMG') {if(el.src.toLowerCase().search(/\.png$/) != -1) {el.isImg = true;el.style.visibility = 'hidden';}else {return;}}else if (el.currentStyle.backgroundImage.toLowerCase().search('.png') == -1) {return;}var lib = PNG;el.vml = {color: {}, image: {}};var els = {shape: {}, fill: {}};for (var r in el.vml) {for (var e in els) {var nodeStr = lib.ns + ':' + e;el.vml[r][e] = document.createElement(nodeStr);}el.vml[r].shape.stroked = false;el.vml[r].shape.appendChild(el.vml[r].fill);el.parentNode.insertBefore(el.vml[r].shape, el);}el.vml.image.shape.fillcolor = 'none'; /* Don't show blank white shapeangle when waiting for image to load. */el.vml.image.fill.type = 'tile'; /* Ze magic!! Makes image show up. */el.vml.color.fill.on = false; /* Actually going to apply vml element's style.backgroundColor, so hide the whiteness. */lib.attachHandlers(el);lib.giveLayout(el);lib.giveLayout(el.offsetParent);/* set up element */lib.applyVML(el);}};
try {document.execCommand("BackgroundImageCache", false, true); /* TredoSoft Multiple IE doesn't like this, so try{} it */
} catch(r) {}
PNG.createVmlNameSpace();
PNG.createVmlStyleSheet();// JavaScript Document

转载于:https://www.cnblogs.com/RightDear/p/3151947.html

ie6不支持png图片的解决办法相关推荐

  1. docx转doc时,防止公式被转成图片的解决办法

    [转载]docx转doc时,防止公式被转成图片的解决办法 编辑社回复需要doc(Word 97-2003)格式的文档,可是将docx(Word 2007+)另存为doc格式时,发现公式被转成了图片.其 ...

  2. xcode 4.2 不再支持 Window-Based Application 的解决办法(转载)

    xcode 4.2 不再支持 Window-Based Application 的解决办法:      1.创建空项目 Empty Application.(在Xcode4.2下创建的这个空项目不再有 ...

  3. [已经验证通过]xp sp2 不支持WPA协议的解决办法

    XP SP2 不支持WPA协议的解决办法 接用户反馈,使用笔记本不能连接无线网络, 据用户反映说他在其它地方能正常连接无线,其它同事也能正常连接无线网络,相当于只有他一台电脑不能连接无线网络. 根据用 ...

  4. 错误 -source 1.6 中不支持 diamond 运算符的解决办法(已解决)

    错误: -source 1.6 中不支持 diamond 运算符的解决办法 第一步:打开setting-> Build.Execution.Deployment 第二步:打开项目结构 开项目结构

  5. html背景图片拉伸解决办法

    html背景图片拉伸解决办法 body {background-size: 100% 100%; //关键代码,直接拉伸背景图background-image: url("img/99.jp ...

  6. php怎么显示不了图片,php显示不了图片的解决办法,

    php显示不了图片的解决办法PHP不能显示图片的解决方案,Php不能显示图片,因为源代码中除了img输出还有其他输出.解决方法是在调用头之前取消任何输出. 推荐: <PHP视频教程> 具体 ...

  7. 关于xlrd最新版本不支持.xlsx文件的解决办法

    文章目录 关于xlrd最新版本不支持.xlsx文件的解决办法 解决方案,回退到xlrd1.2.0版本 这是很久之前我就遇到的一个问题,这次又遇到了,发现之前没有写笔记,这次记录一下. 关于xlrd最新 ...

  8. png在IE6下去除显示阴影的解决办法

    png在IE6下的解决办法 默认分类 2010-08-23 23:58:12 阅读50 评论0   字号:大 中 小   订阅 [转自:http://blog.csdn.net/newflypig/a ...

  9. IE6不支持PNG图片透明效果的完美解决方案(完善版)

    可怜的IE6,不支持PNG图片透明, 这已经是其众多"BUG"中,不是那么显眼的一个, 但也是让部分人头痛的一个了. (今天在机房那破机器上IE6忘了抓图了,现在想给大家看效果也难 ...

最新文章

  1. CentOS7安装配置redis-3.0.0
  2. AI学术大地震---YOLO之父退出CV界,以此来反对AI算法用于军事和隐私窥探
  3. 吴恩达机器学习笔记 —— 16 异常点检测
  4. OpenERP Web开发
  5. jquery 判断手势滑动方向(上下左右)
  6. java中数据类型转换、ASCII编码
  7. NOIP2018游记题解
  8. TensorFlow 学习指南 一、基础
  9. Java基础学习总结(79)——Java本地接口JNI详解
  10. php xml三级联动,jquery+xml实现三级联动步骤详解
  11. 研发项目wbs分解简单案例_2013项目管理案例分析:工作分解结构(WBS)(精选五篇)...
  12. WGS84地球坐标系,GCJ02火星坐标系,BD09百度坐标系简介与转换
  13. ps和matlab哪个,Matlab与photoshop在数字图像处理中的比较
  14. Linux进程虚拟内存大 性能,Linux进程分析(一) 虚拟内存和物理内存
  15. Python项目实战:爬取糗事百科最热门的内涵搞笑段子
  16. 华师大副校长任友群:互联网+校园新挑战
  17. java fuoco车架_为速度而生 JAVA Fuoco铝合金气动公路
  18. QT INSTALLS使用
  19. Mac下压缩和解压rar文件的方法
  20. JUnit 5 测试 Spring 引擎的时候提示 junit-vintage 错误

热门文章

  1. fetch ajax cros,由 Fetch 跨域 看 CORS
  2. json转为tfrecord格式文件怎么转_word怎么转换成pdf格式?这样转很方便
  3. apollo修改配置刷新bean_微服务配置中心完全解读
  4. 剑指 Offer 13. 机器人的运动范围 【重刷】
  5. 【Elasticsearch】Elasticsearch性能调优:千万不要做愚蠢的事
  6. 【elasticsearch】ClusterBlockException[blocked by: [FORBIDDEN/12/index read-only / allow delete (api)]
  7. 【Mac】Mac iTerm2 使用笔记 远程连接
  8. 95-090-022-源码-bin脚本-CLI提交Job的时候加载插件
  9. Hadoop DataNode : Address already in use
  10. 【安全】LDAP是轻量目录访问协议,英文全称是Lightweight Directory Access Protocol