天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

PNGHandler-借助JS讓PNG圖在IE下實(shí)現(xiàn)透明(包括背景圖)

PNG.JS代碼:
// PNGHandler: Object-Oriented Javascript-based PNG wrapper
// --------------------------------------------------------
// Version 1.1.20031218
// Code by Scott Schiller - www.schillmania.com
// --------------------------------------------------------
// Description:
// Provides gracefully-degrading PNG functionality where
// PNG is supported natively or via filters (Damn you, IE!)
// Should work with PNGs as images and DIV background images.

function PNGHandler() {
 var self = this;

 this.na = navigator.appName.toLowerCase();
 this.nv = navigator.appVersion.toLowerCase();
 this.isIE = this.na.indexOf('interNET explorer')+1?1:0;
 this.isWin = this.nv.indexOf('windows')+1?1:0;
 this.ver = this.isIE?parseFloat(this.nv.split('msie ')[1]):parseFloat(this.nv);
 this.isMac = this.nv.indexOf('mac')+1?1:0;
 this.isOpera = (navigator.userAgent.toLowerCase().indexOf('opera ')+1 || navigator.userAgent.toLowerCase().indexOf('opera/')+1);
 if (this.isOpera) this.isIE = false; // Opera filter catch (which is sneaky, pretending to be IE by default)

 this.transform = null;

 this.getElementsByClassName = function(className,oParent) {
 doc = (oParent||document);
 matches = [];
 nodes = doc.all||doc.getElementsByTagName('*');
 for (i=0; i<nodes.length; i++) {
 if (nodes[i].className == className || nodes[i].className.indexOf(className)+1 || nodes[i].className.indexOf(className+' ')+1 || nodes[i].className.indexOf(' '+className)+1) {
 matches[matches.length] = nodes[i];
 }
 }
 return matches; // kids, don't play with fire. ;)
 }

 this.filterMethod = function(oOld) {
 // IE 5.5+ proprietary filter garbage (boo!)
 // Create new element based on old one. Doesn't seem to render properly otherwise (due to filter?)
 // use proprietary "currentStyle" object, so rules inherited via CSS are picked up.

 var o = document.createElement('div'); // oOld.nodeName
 var filterID = 'DXImageTransform.Microsoft.AlphaImageLoader';
 // o.style.width = oOld.currentStyle.width;
 // o.style.height = oOld.currentStyle.height;

 if (oOld.nodeName == 'DIV') {
 var b = oOld.currentStyle.backgroundImage.toString(); // parse out background image URL
 oOld.style.backgroundImage = 'none';
 // Parse out background image URL from currentStyle object.
 var i1 = b.indexOf('url("')+5;
 var newSrc = b.substr(i1,b.length-i1-2).replace('.gif','.png'); // find first instance of ") after (", chop from string
 o = oOld;
 o.style.writingMode = 'lr-tb'; // Has to be applied so filter "has layout" and is displayed. Seriously. Refer to http://msdn.microsoft.com/workshop/author/filter/reference/filters/alphaimageloader.ASP?frame=true
 o.style.filter = "progid:"+filterID+"(src='"+newSrc+"',sizingMethod='crop')";
 // Replace the old (existing) with the new (just created) element.
 // oOld.parentNode.replaceChild(o,oOld);
 } else if (oOld.nodeName == 'IMG') {
 var newSrc = oOld.getAttribute('src').replace('.gif','.png');
 // apply filter
 oOld.src = 'none.gif'; // get rid of image
 oOld.style.filter = "progid:"+filterID+"(src='"+newSrc+"',sizingMethod='crop')";
 oOld.style.writingMode = 'lr-tb'; // Has to be applied so filter "has layout" and is displayed. Seriously. Refer to http://msdn.microsoft.com/workshop/author/filter/reference/filters/alphaimageloader.ASP?frame=true
 }
 }

 this.pngMethod = function(o) {
 // Native transparency support. Easy to implement. (woo!)
 bgImage = this.getBackgroundImage(o);
 if (bgImage) {
 // set background image, replacing .gif
 o.style.backgroundImage = 'url('+bgImage.replace('.gif','.png')+')';
 } else if (o.nodeName == 'IMG') {
 o.src = o.src.replace('.gif','.png');
 } else if (!this.isMac) {
 // window.status = 'PNGHandler.applyPNG(): Node is not a DIV or IMG.';
 }
 }

 this.getBackgroundImage = function(o) {
 var b, i1; // background-related variables
 var bgUrl = null;

 if (o.nodeName == 'DIV' && !(this.isIE && this.isMac)) { // ie:mac PNG support broken for DIVs with PNG backgrounds
 if (document.defaultView) {
 if (document.defaultView.getComputedStyle) {
 b = document.defaultView.getComputedStyle(o,'').getPropertyValue('background-image');
 i1 = b.indexOf('url(')+4;
 bgUrl = b.substr(i1,b.length-i1-1);
 } else {
 // no computed style
 }
 } else {
 // no default view
 }
 }
 return bgUrl;
 }

 this.supportTest = function() {
 // Determine method to use.
 // IE 5.5+/win32: filter

 if (this.isIE && this.isWin && this.ver >= 5.5) {
 // IE proprietary filter method (via DXFilter)
 self.transform = self.filterMethod;
 } else if (!this.isIE && this.ver < 5) {
 self.transform = null;
 // No PNG support or broken support
 // Leave existing content as-is
 } else if (!this.isIE && this.ver >= 5 || (this.isIE && this.isMac && this.ver >= 5)) { // version 5+ browser (not IE), or IE:mac 5+
 self.transform = self.pngMethod;
 } else {
 // Presumably no PNG support. GIF used instead.
 self.transform = null;
 return false;
 }
 return true;
 }

 this.init = function() {
 if (this.supportTest()) {
 this.elements = this.getElementsByClassName('png');
 for (var i=0; i<this.elements.length; i++) {
 this.transform(this.elements[i]);
 }
 }
 }

}

// Instantiate and initialize PNG Handler

var pngHandler = new PNGHandler();

DEMO頁HTML代碼:
<html>
<head>
<title>Schillmania! | png.js demo</title>
<script type="text/Javascript" src="png.js"></script>
</head>

<body>

<!--

 Don't copy this part here, this is just for your information.

 // Required under the <head> tag:

 <script type="text/Javascript" src="png.js"></script>

 // Required in the <body> tag:

 <img src="your-image.gif" class="png" style="width:XXXpx;height:YYYpx" />

 // ..Where XXX and YYY are the width/height of your image. Without width/height the PNG won't work under IE:win32.

 // Required before the </body> tag (but after all of your content):

 <script type="text/Javascript">
 pngHandler.init();
 </script>

 // This Javascript block should be put at the bottom of your page, inside the <body> and before </body>.
 // It calls the library and replaces the GIF images (if applicable) before the page has loaded (and before the GIF has loaded, So the user doesn't load 2 images for each PNG you want to replace.)
 // If you don't put it after all of your content, it may do strange things and miss some images.

-->

<h1>PNG (img)</h1>

<img src="foo.gif" alt="" class="png" style="width:220px;height:100px" />

<h1>PNG (div with background image)</h1>

<div class="png" style="width:220px;height:100px;background-image:url(foo.gif);background-repeat:no-repeat">
  
</div>

<script type="text/Javascript">
 pngHandler.init();
</script>

</body>
</html>

源碼及DEMO打包下載:
本地下載

JavaScript技術(shù)PNGHandler-借助JS讓PNG圖在IE下實(shí)現(xiàn)透明(包括背景圖),轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 中文字幕国产在线观看 | 最近2018年手机中文字幕 | 国产 在线 亚洲 欧美 动漫 | 亚洲精品电影久久久影院 | 男女作爱在线播放免费网页版观看 | 日韩精品一区二区亚洲AV观看 | 亚洲午夜电影 | 手机在线成人精品视频网 | 夜夜女人国产香蕉久久精品 | 久久这里只有精品2 | 亚洲欧美韩国综合色 | av网站视频在线观看 | 麻豆成人久久精品二区三区网站 | 婷婷久久综合九色综合伊人色 | 国产在线观看99 | 簧片在线观看 | 亚洲日韩天堂在线中文字幕 | 亚洲欧美在无码片一区二区 | 亚洲一区二区三区高清网 | 欧美精品一区二区三区视频 | 男女爽爽无遮挡午夜视频在线观看 | 18黄女脱内衣 | 国产亚洲精品久久久久久无码网站 | gay台湾无套男同志xnxⅹ | 97人妻AV天天澡夜夜爽 | 驯服有夫之妇HD中字日本 | 国产69精品久久久久APP下载 | 日韩视频在线观看 | 曰批视频免费40分钟不要钱 | 亚洲国产精品无码2019 | 香蕉动漫库 | 最新亚洲中文字幕在线观看 | 香蕉久久夜色精品国产小说 | 男人私gay挠脚心vk视频 | 国产成人精选免费视频 | 俄罗斯6一9泑女网站 | 无毒成人社区 | 伊人久久99热这里只有精品 | 一区二区三区毛AAAA片特级 | 俄罗斯aaaaa一级毛片 | 狠狠干.in|