search
HomeWeb Front-endJS TutorialPNG related functions under IE browser_javascript skills

At present, the Internet has higher and higher requirements for web page effects, and it is inevitable to use PNG images. PNG is divided into several formats, PNG8, PNG24, PNG32, among which the most commonly used one, which also has moderate display effect and size, is PNG24. It supports translucency, transparency, and very rich colors. However, because most of our Chinese people use the IE series or browsers with IE as the core series, and because WINDOWS XP has a relatively large market share in the domestic market, and many people are still using XP. IE6 IE7 IE8 and other browsers, and these browsers have more or less gaps in their support for PNG. IE6 does not support PNG at all, and IE7 IE8 supports PNG incompletely. When changing the transparency of an image under IE7 IE8, PNG will not be supported. There will be a black border in the transparent area. If it is translucent, the entire translucent area will be black. This is unacceptable for pages that require beautiful appearance. After some research, I found that using PNG as the background, use Microsoft The unique filter loads images, which can solve the problem of IE6 not supporting PNG, and can also solve the problem of black edges when using JQUERY animation transparency effect under IE7 and IE8. There is a code with a real image, as follows:

<script>
function correctPNG() {
  var arVersion = navigator.appVersion.split("MSIE")
  var version = parseFloat(arVersion[1])
  if ((version >= 5.5) && (document.body.filters)) {
    var lee_i = 0;
    var docimgs=document.images;
    for (var j = 0; j < docimgs.length; j++) {
      var img = docimgs[j]
      var imgName = img.src.toUpperCase();
      if (imgName.substring(imgName.length - 3, imgName.length) == "PNG" && !img.getAttribute("usemap")) {
        lee_i++;
        var SpanID = img.id || 'ra_png_' + lee_i.toString();
        var imgData = new Image();
        imgData.proData = SpanID;
        imgData.onload = function () {
          $("#" + this.proData).css("width", this.width + "px").css("height", this.height + "px");
        }
        imgData.src = img.src;
        var imgID = "id='" + SpanID + "' ";
        var imgClass = (img.className) &#63; "class='" + img.className + "' " : ""
        var imgTitle = (img.title) &#63; "title='" + img.title + "' " : "title='" + img.alt + "' "
        var imgStyle = "display:inline-block;" + img.style.cssText
        if (img.align == "left") imgStyle = "float:left;" + imgStyle
        if (img.align == "right") imgStyle = "float:right;" + imgStyle
        if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
        var strNewHTML = "<span " + imgID + imgClass + imgTitle
       + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
       + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
       + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
        img.outerHTML = strNewHTML;
        j = j - 1;
      }
    }
  }
}
//判断是否为IE8及以下浏览器,其实除了这三个浏览器不支持addEventListener,其它浏览器都没问题
if (typeof window.addEventListener == "undefined" && typeof document.getElementsByClassName == "undefined") {
  window.attachEvent("onload", correctPNG);
}
</script>

Reference the jquery1.8 class library before the end tag of /body of the page, and then add the above code. There is no problem displaying PNG24 in IE6 7 8. If you need to perform animate animation or obtain pictures, you will find that in IE 6 7 8 times, the PNG image cannot be found, or there is no response when changing its position and transparency. The reason is that correctPNG replaces the IMG tags of all PNGs on the page with SPAN tags, and then uses filter: progid on the SPAN tags. :DXImageTransform.Microsoft.AlphaImageLoader loads the PNG image, so the recommended approach is to include the image in a DIV. Only one IMG tag is allowed in this DIV, and then perform position or transparency related operations on the DIV, for example:

<div id='test'><img  class="share-list-icon-shadow lazy"  src="/static/imghwm/default1.png"  data-src="style/images/icon-shadow.png" / alt="PNG related functions under IE browser_javascript skills" ></div>
<script>
$("#test").animate({opacity:0.2,marginLeft:500},1000,function(){alert('run complete');});
</script>

Another situation is that in addition to transparency and displacement of this image, I also need to change its width and height. In this case, I recommend the following method:

<div id="test"><img  class="share-list-icon-shadow lazy" src="/static/imghwm/default1.png" data-src="style/images/icon-shadow.png" alt="PNG related functions under IE browser_javascript skills" ></div>
<script>
$($("#test span")[0]||$("#test img")[0]).animate({opacity:0.2,marginLeft:500,width:'500px',height:'500px'},1000,function(){alert('run complete');});
</script>

BUG: If you dynamically modify the transparency of a png image under IE7 and IE8, for example, if you apply a fadeIn and adjust the transparency of the image to 25%, a very strange bug will appear. The transparency information of the png will not be displayed. Got it! It turned into a very ugly black color!

Solution to the bug where the background of png images turns black under IE7 and IE8:

1. Don’t change the transparency of the image directly, but put a container for the image to modify the transparency of the container
For example, the original code is:

Modify to:

2. Add a background color to this container

It is very important. The key to solving bugs lies in this step, such as:

.share-list-icon-shadow{ 
  width:60px;height:21px; 
  position:absolute;bottom:8px;left:0px;z-index: 1; 
  margin: 0 auto; 
  display:block; 
  background:#FAFDEF; 
} 

Under normal circumstances, the bug is solved at this point. If you still have problems, please see below:

3. Add zoom to the container: 1

zoom: 1 What role does it play? Why does IE have this bug?
These are two questions, but actually one answer. IE modifies transparency not through CSS attributes, but through filters. Therefore, if you want to understand this bug, you must find the reason from the filters. When filter acts on an object, the object must be tangible, that is, it must be a layout. IE has a very special attribute: hasLayout. This attribute can be given to the container as a layout. The hasLayout attribute is a bit strange. You cannot write it directly. css starts, but it must be started through javascript. In fact, there is another way to start, which is to use a special css attribute to start hasLayout in disguise. This css attribute is zoom (other attributes such as display:inline-block, float:left, etc. are also OK, but only zoom has no side effects)

The above is the entire content of this article, I hope you all like it.

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
手机怎么改联通wifi密码手机怎么改联通wifi密码Jan 30, 2024 pm 09:24 PM

联通光猫自带wifi修改密码1、输入后记得保存哦,因为这个就是你新创建或修改后的WIFI账号和密码了。安防移动光猫初始密码:123456或者是默认的用户名admin,密码也是adminip地址是19161。2、联通无线网络WiFi密码的设置方法:打开电脑的wifi,搜索光猫默认wifi名(路由器背面铭牌有写),连接wifi网络。打开电脑浏览器,输入光猫背后铭牌的网关ip地址(一般是19161),进入网关配置界面。3、河南地市的联通用户,在宽带、光猫或机顶盒使用过程中如遇问题,可拨打96480宽带

如何确定IE浏览器的安装路径如何确定IE浏览器的安装路径Jan 30, 2024 pm 05:18 PM

怎样查看IE浏览器的安装位置?我们想要查看Ie浏览器的安装位置要如何查看,下面介绍下方法步骤!我们会经常使用IE浏览器浏览网页,有些小伙伴想知道电脑上的IE浏览器安装在那个目录上,但是不知道应该如何查找,具体的方法步骤是什么,小编下面整理了查看IE浏览器的安装位置方法步骤,如果你不会操作的话,跟着我一起往下看看吧!查看IE浏览器的安装位置方法步骤1、按下键盘上的“win”键打开开始菜单栏并在开始菜单栏的搜索框中输入“i”2、可以看到搜索结果中已经出现内容了,在搜索结果中找到“Internetex

ie阻止了此网站安装ActiveX控件怎么办ie阻止了此网站安装ActiveX控件怎么办Mar 23, 2023 pm 03:54 PM

ie阻止了此网站安装ActiveX控件的解决办法:1、打开ie10,点击右上角“工具”按钮,选择“internet选项”;2、在弹出的“internet选项”窗口上,依次选择“安全->受信任站点->站点”;3、将所需要打开的网站添加到信任站点;4、点击“自定义级别”按钮,在弹出的窗口上把所有的“ActiveX”项都勾选为“启用”即可。

解决IE浏览器按钮无响应的方法解决IE浏览器按钮无响应的方法Jan 30, 2024 am 10:48 AM

IE浏览器点击网页按钮没有反应怎么办?我们在点击网页按钮没有反应的话,可以在兼容性视图中进行设置!有小伙伴在使用IE浏览器的时候,发现点击网页中的按钮,浏览器不会有任何的反应,这样我们就无法使用该网页的功能,我们可以怎么样设置,小编下面整理了IE浏览器点击网页按钮没有反应解决办法,不会的话跟着我一起往下看吧!IE浏览器点击网页按钮没有反应解决办法1、打开IE浏览器,点击操作栏上【工具】按钮,并点击【兼容性视图】设置,如图所示。2、在【兼容性视图】设置页面中,点击右边的【添加】按钮,将该网站填入,

win10系统安装不了ie浏览器怎么办win10系统安装不了ie浏览器怎么办Jun 29, 2023 pm 04:24 PM

win10系统安装不了ie浏览器怎么办?电脑系统在升级到win10之后,原本默认的ie浏览器就变成了升级版的edge浏览器,而原本的ie浏览器就无法装上了,虽然edge浏览器的各方面比ie浏览器更好,但有些用户还是想要换回ie浏览器,下面就由小编为大家带来win10系统安装不了ie浏览器解决方法。win10系统安装不了ie浏览器解决方法1、打开win10电脑桌面,按下“win”+“R”键打开运行菜单,输入“control”确定打开控制面板。2、设置查看方式为“类别”,然后点击“程序”进入程序控制

教你如何在Win11中恢复IE11浏览器教你如何在Win11中恢复IE11浏览器Jan 29, 2024 pm 02:00 PM

win11作为最新的操作系统,相信不少的用户们都已经下载使用了,也有不少的用户们在询问小编win11怎么恢复ie11浏览器?用户们可以选择命令提示符然后直接的输入Netshwinsockreset和netshadvfirewallreset来进行设置就可以了。下面就让本站来为用户们来仔细的介绍一下win11恢复IE浏览器的操作方法吧。win11恢复IE浏览器的操作方法4、完成之后关闭命令框,重启系统就可以了。还可以尝试以下方法:方法1在浏览器设置中点击左侧默认浏览器选项,然后在弹出的页面中打开允

打开IE浏览器强制跳转edge怎么设置关闭打开IE浏览器强制跳转edge怎么设置关闭Jan 31, 2024 pm 12:57 PM

打开IE浏览器强制跳转edge怎么设置关闭?edge浏览器是由微软公司推出的IE浏览器的完全升级版,因此我们在开启IE浏览器的时候,会强制跳转到edge浏览器中。但有些IE浏览器的老用户更习惯使用IE浏览器,不喜欢跳转到edge浏览器,这是我们可以通过设置来取消掉二者的关联。如果你不懂的该怎么操作的话,就随小编一起来看看IE自动跳转edge设置取消的方法介绍吧。打开IE浏览器强制跳转edge怎么设置关闭方法一:internet选项高级1、首先在电脑中找到“控制面板”,并在界面中找到“intern

ie浏览器不弹出保存密码提醒怎么办ie浏览器不弹出保存密码提醒怎么办Jan 30, 2024 pm 08:21 PM

ie浏览器不弹出保存密码提醒怎么办?我们在使用ie浏览器的时候,输入密码不提示保存密码的提醒应该如何设置。我们平时使用ie浏览器的时候,登录账号密码都会跳出询问我们是否保存密码,但是有小伙伴近期在使用ie浏览器的时候,发现没有这个提醒了,想知道应该如何设置,小编下面整理了ie浏览器不弹出保存密码解决教程,不会的话跟着我一起往下看吧!介绍ie浏览器不弹出保存密码解决教程1、打开ie安全浏览器,点击“工具”,然后选择“internet选项”,如图所示。2、切换至内容选项卡在internet属性窗口中

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software