First, new naturalwidth and Naturalheight attributes in HTML5
In HTML 5, the new two attributes are added to determine the width and height of the image, respectively, the Naturalwidth and Naturalheight properties,
Examples are as follows:
var // Real picture width var // true real picture height
The premise is that the images must be fully downloaded to the client browser to be judged, and currently available in IE 9,firefox, Chrome, Safari and opera.
Second, if it is not supported version of the browser, it can be judged by the traditional method
examples are as follows:
varMyImage = document.getElementById ("MyImage");if(typeofMyimage.naturalwidth = = "undefined") {//IE 6/7/8 vari =NewImage (); I.SRC=myimage.src; varRW =I.width; varRH =i.height;}Else{//HTML5 Browsers varRW =Myimage.naturalwidth; varRH =myimage.naturalheight;}
JS get the original size of the picture