1) Get picture size
Copy Code code as follows:
<script>
function Getwh (t) {
Dom Properties
Console.log ("width=" +t.width);//200
Console.log ("height=" +t.height);//300
Action Style
Console.log ("stylewidth=" +t.style.width);
Console.log ("styleheight=" +t.style.height);
}
2 Get picture size (not set width height)
Copy Code code as follows:
<script>
function Getwh (t) {
Dom Properties
Console.log ("width=" +t.width);//200
Console.log ("height=" +t.height);//300
Action Style
Console.log ("stylewidth=" +t.style.width);
Console.log ("styleheight=" +t.style.height);
}
As long as we do not explicitly set it in style, the width of the height is always empty!
3) Enlarge the picture:
Here we use IE's private property to prevent image amplification distortion serious!
Copy Code code as follows:
<script>
function Getwh (t) {
T.width *= 2;
T.height *= 2;
Once per click, the width and height are magnified one times
}
</script>
4 in FF and Google, we can also use Naturalwidth and naturalheight to get the original size of the picture!
Copy Code code as follows:
<script>
function Getwh (t) {
Console.log ("width=" +t.naturalwidth);
Console.log ("height=" +t.naturalheight);
T.width = T.naturalwidth * 2;
T.height = T.naturalheight * 2;
}
</script>
Naturalwidth and Naturalheight are only read-only properties and cannot be used to set the size of the picture and cannot be magnified continuously.