在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 added
lots of other stylesheets using document.createStyleSheet
and 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

ie6不支持png图片的解决办法的更多相关文章

  1. IE6不支持li:hover的解决办法,一句代码让IE6支持li:hover

    如果不是因为工作需要,我根本不会理会IE6的兼容问题,甚至我都不想理会IE的所有内核,不过IE9用了下,我还是重新对IE报以期待的.话题扯远了,下面回到话题上来吧.这次要说的内容就是,如果让IE支持l ...

  2. IE6/IE7下margin-bottom失效兼容解决办法及双倍边距问题

    (从已经死了一次又一次终于挂掉的百度空间人工抢救出来的,发表日期 2014-04-08) 一.IE6/IE7下margin-bottom失效兼容解决办法 1.用padding-bottom代替:2.在 ...

  3. win10 家庭版不支持gpedit.msc的解决办法

    win10 家庭版不支持gpedit.msc的解决办法 1.建立一个批处理文件内容如下: @echo off pushd "%~dp0" dir /b %systemroot%\W ...

  4. IE6 验证码刷新失败显示空白解决办法

    原因:点击a标签看不清?换图片 结果验证码显示的空白! 解决办法:在对应的点击事件最后加上return false 即可解决问题. 下面是HTML源码: <p class="regis ...

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

    编辑社回复需要doc(Word 97-2003)格式的文档,可是将docx(Word 2007+)另存为doc格式时,发现公式被转成了图片.其实,最简单的办法就是,打个电话过去给编辑社:“大爷,拜托您 ...

  6. hexo + typora 图片插入解决办法

    Typora 是一款知名的 Markdown 编辑器,简单好用,体验良好.使用 hexo 搭建好博客后,主要是用 Markdown 来编写博客,typora 便是我的首选编辑器.但直接使用 typor ...

  7. WCF不支持 ASP.NET 兼容性 解决办法

    错 误提示:无法激活服务,因为它不支持 ASP.NET 兼容性.已为此应用程序启用了 ASP.NET 兼容性.请在 web.config 中关闭 ASP.NET 兼容性模式或将 AspNetCompa ...

  8. IE6不支持position:fixed的解决方法

    解决IE6不支持position:fixed的方法,非常简单,具体调用请参考下面: /*让position:fixed在IE6下可用! */ .fixed-top /* 头部固定 */{positio ...

  9. ECSHOP后台编辑器不能上传中文名图片的解决办法

    在后台上传商品图片的时候,如果你选择一个中文名称的图片,那么上传后会产生乱码,导致图片显示不出来. 下面说一种解决办法: 使用“年月日时分秒 + 6个随机字符”做为文件名,如 201010161356 ...

随机推荐

  1. 为公司内部搭建CA

    步骤一 首先我们要知道CA的配置文件 openssl的配置文件:/etc/pki/tls/openssl.cnf 我们打开这个配置文件 这文件中很多跟CA相关的信息如图 解释: 我们可以搭建好几个CA ...

  2. (二十一)python 3 内置函数

    阅读目录 1.abs() 2.dict() 3.help() 4.min() 5.setattr() 6.all() 7.dir() 8.hex() 9.next() 10.slice() 11.an ...

  3. POJ 1383 Labyrinth (树的直径求两点间最大距离)

    Description The northern part of the Pyramid contains a very large and complicated labyrinth. The la ...

  4. php添加了环境变更,还是显示 不是内部或外部命令 (注:添加到目录即可,不加 php.exe )

    重新配置了PHP环境,要安全PEAR扩展,CMD窗口运行PHP,提示不是内部或者外部命令或者可执行文件,解决方法是把PHP目录加入系统环境变量,不然的话,你只能CD到PHP安装目录下来运行PHP命令.

  5. CTO俱乐部官方群聊-探讨创业和跳槽

     今天,CTO俱乐部官方群,有交流,若干活跃分子探讨了创业和跳槽等相关话题. 感觉质量很不错,就整理了下. 老徐 17:02:00  跳来跳去也不是长久之计,除了涨点工资   张苗苗 17:02:46 ...

  6. 大数据学习——hdfs客户端流式操作代码的实现

    package cn.itcast.bigdata.hdfs.diceng; import org.apache.hadoop.conf.Configuration; import org.apach ...

  7. 70.打印所有Spring boot载入的bean【从零开始学Spring Boot】

    [从零开始学习Spirng Boot-常见异常汇总] 问题的提出: 我们在开发过程当中,我们可能会碰到这样的问题:No qualifying bean  就是我们定义的bean无法进行注入,那到底是什 ...

  8. POJ-2689 Prime Distance,区间素数筛法

                                                    Prime Distance 只会埃氏筛法的弱鸡今天读了读挑战程序设计120页,明白了求小区间内素数的方 ...

  9. 什么是Service Mesh?

    转至大佬宋净明的博客:https://jimmysong.io/posts/what-is-a-service-mesh/ Service mesh 又译作 “服务网格”,作为服务间通信的基础设施层. ...

  10. bzoj 1503[NOI 2004] 郁闷的出纳员

    题目大意: 给4种操作 I:添加一个员工工资信息 A:增加所有员工的工资 S:减少所有员工的工资 F:询问工资第k高的员工的工资情况 自己做的第一道splay树的题目,初学找找感觉 #include ...