This example describes the way JavaScript simply gets the original size of a page picture. Share to everyone for your reference, specific as follows:
This gets the original width-height through the image () object
This way is not so troublesome, direct new image () object, and then the IMG src assignment to him can be obtained.
var img = new Image ();
IMG.SRC = $ ("#target"). attr ("src");
if (img.complete) {
alert (' Width: ' +img.width+ ', height ' +img.height);
img = null;
} else{
img.onload = function () {
alert (' Width: ' +img.width+ ', height ' +img.height);
img = null;}
;
}
And do not worry about the new image object will be more than one HTTP request, the browser load the picture has been cached, you new N image objects are no problem, of course, memory will be consumed, so after using the IMG to NULL.
More readers interested in JavaScript-related content can view the site topics: "JavaScript switching effects and tips summary", "JavaScript Search Algorithm Skills Summary", "JavaScript animation effects and tips summary", " JavaScript error and debugging skills Summary, JavaScript data structure and algorithm skills summary, JavaScript traversal algorithm and skills summary and JavaScript mathematical calculation usage Summary
I hope this article will help you with JavaScript programming.