This article describes the method of simply obtaining the original size of a page image in JavaScript. Share it for your reference, as follows:
Here, the original width and height are obtained through the Image() object
This method is not that troublesome. You can directly new an Image() object and assign img's src to it to get it.
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 don't worry about the new Image object having an extra http request. The browser has a cache after loading the image. It's OK to have new N image objects. Of course, memory will be consumed, so after using it, img is set to null.
For more information about JavaScript related content, please check out the topics of this site: "Summary of JavaScript switching effects and techniques", "Summary of JavaScript search algorithm skills", "Summary of JavaScript animation effects and techniques", "Summary of JavaScript errors and debugging techniques", "Summary of JavaScript data structures and algorithm skills", "Summary of JavaScript traversal algorithms and techniques", and "Summary of JavaScript mathematical operations usage"
I hope this article will be helpful to everyone's JavaScript programming.