JS taken pictures of the original width and height, compatible IE7,8

naturalWidth and naturalHeight can directly obtain the original img width and height, and innerHight, innerWith just get the picture width and height occupied by the container box.

// 封装
function
getNaturalSize (DomElement) { var natureSize = {}; if(window.naturalWidth && window.naturalHeight) { natureSize.width = DomElement.naturalWidth; natureSizeheight = DomElement.naturalHeight; } else { var img = new Image(); img.src = DomElement.src; natureSize.width = img.width; natureSizeheight = img.height; } return natureSize; } // 使用 var natural = getNaturalSize (document.getElementById('img')), natureWidth = natural.width, natureHeight = natural.height;

 

Guess you like

Origin www.cnblogs.com/panax/p/10937853.html