IE 6透明PNG修复-SuperSlight

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了IE 6透明PNG修复-SuperSlight相关的知识,希望对你有一定的参考价值。

Getting SuperSleight running on a page is quite straightforward, you just need to link the supplied javascript file into your document inside conditional comments so that it is delivered to only Internet Explorer 6 or older.
  1. var supersleight = function() {
  2.  
  3. var root = false;
  4. var applyPositioning = true;
  5.  
  6. // Path to a transparent GIF image
  7. var shim = 'x.gif';
  8.  
  9. // RegExp to match above GIF image name
  10. var shim_pattern = /x.gif$/i;
  11.  
  12.  
  13.  
  14. var fnLoadPngs = function() {
  15. if (root) {
  16. root = document.getElementById(root);
  17. }else{
  18. root = document;
  19. }
  20. for (var i = root.all.length - 1, obj = null; (obj = root.all[i]); i--) {
  21. // background pngs
  22. if (obj.currentStyle.backgroundImage.match(/.png/i) !== null) {
  23. bg_fnFixPng(obj);
  24. }
  25. // image elements
  26. if (obj.tagName=='IMG' && obj.src.match(/.png$/i) !== null){
  27. el_fnFixPng(obj);
  28. }
  29. // apply position to 'active' elements
  30. if (applyPositioning && (obj.tagName=='A' || obj.tagName=='INPUT') && obj.style.position === ''){
  31. obj.style.position = 'relative';
  32. }
  33. }
  34. };
  35.  
  36. var bg_fnFixPng = function(obj) {
  37. var mode = 'scale';
  38. var bg = obj.currentStyle.backgroundImage;
  39. var src = bg.substring(5,bg.length-2);
  40. if (obj.currentStyle.backgroundRepeat == 'no-repeat') {
  41. mode = 'crop';
  42. }
  43. obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')";
  44. obj.style.backgroundImage = 'url('+shim+')';
  45. };
  46.  
  47. var el_fnFixPng = function(img) {
  48. var src = img.src;
  49. img.style.width = img.width + "px";
  50. img.style.height = img.height + "px";
  51. img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')";
  52. img.src = shim;
  53. };
  54.  
  55. var addLoadEvent = function(func) {
  56. var oldonload = window.onload;
  57. if (typeof window.onload != 'function') {
  58. window.onload = func;
  59. } else {
  60. window.onload = function() {
  61. if (oldonload) {
  62. oldonload();
  63. }
  64. func();
  65. };
  66. }
  67. };
  68.  
  69. return {
  70. init: function() {
  71. addLoadEvent(fnLoadPngs);
  72. },
  73.  
  74. limitTo: function(el) {
  75. root = el;
  76. },
  77.  
  78. run: function() {
  79. fnLoadPngs();
  80. }
  81. };
  82. }();
  83.  
  84. // limit to part of the page ... pass an ID to limitTo:
  85. // supersleight.limitTo('header');
  86.  
  87. supersleight.init();

以上是关于IE 6透明PNG修复-SuperSlight的主要内容,如果未能解决你的问题,请参考以下文章

JavaScript IE 6透明PNG修复 - SuperSleight

IE 5.5和6的透明PNG修复程序

CSS 适用于IE 5.5和6的透明PNG修复程序

css IE6的透明PNG修复

CSS IE修复:嵌入PNG透明度

CSS IE修复:背景PNG透明度