Home > Web Front-end > JS Tutorial > Web page standards, what should I do if IMG does not support the onload tag_JavaScript

Web page standards, what should I do if IMG does not support the onload tag_JavaScript

WBOY
Release: 2016-05-16 19:28:33
Original
1208 people have browsed it

Web page standards, what should I do if IMG does not support the onload tag

I remember someone asked me this before, but I didn’t pay attention to it at that time. Now I finally encountered this problem. Because the img tag does not have an onload event. So the img in the UBB code uses onload to handle large This method cannot be used to adapt the image to the image.
But after testing, the body can still bring the onload event, so my solution is to process the image that is too large after the page is fully loaded.

So I wrote a simple code in JS
Related codes

function ReImgSize(){
for (j=0;j{
document.images[j].width=(document.images[j] .width>420)?"420":document.images[j].width;
}
}



Then add onload="ReImgSize( " Image adaptation.
We all know that Mozilla supports a max-width CSS syntax. So, we define the global style of the image like this



Related code
img{
max-width:100%;height:auto;
}

In this way, the image will automatically adapt to its size within the div or table.
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template