Home > Web Front-end > JS Tutorial > body text

Use js to get the original size of the image_javascript skills

WBOY
Release: 2016-05-16 16:29:26
Original
1177 people have browsed it

The size of the image displayed in the browser may not be its actual height and width. For example, as shown below, we add width and height styles to it

The size displayed in the browser is 25px. So how do we get the true size of the image? , the following code implements this function

Copy code The code is as follows:




            


                                                                                                                                                                                                                                                                                        //Set a delay to ensure that the image is loaded
                setTimeout(function() {
              var
                                              real_width,
                    real_height,
                                                                                                                                                                                                                                               _im                                                                                                                                                                                                          through                                                                                                                                                                                                                                                                      real_width = im.width,
                                       real_height = im.height;
alert(real_width 'n' real_height);
             },500);
                                                                                         




Note: I have tested the above code on both IE7 and chrome. Since IE6 is not installed, I cannot test it.

Very easy to use code, I use it in most of my projects, feel free to use it
Related labels:
js
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