我正在创建一个jQuery插件.
如何在Safari中使用Javascript获得真实的图像宽度和高度?
以下适用于Firefox 3,IE7和Opera 9:
var pic = $("img")
// need to remove these in of case img-element has set width and height
pic.removeAttr("width");
pic.removeAttr("height");
var pic_real_width = pic.width();
var pic_real_height = pic.height();
Run Code Online (Sandbox Code Playgroud)
但在像Safari和Google Chrome这样的Webkit浏览器中,值为0.
我想知道如何获得元素的比例值?
我试过$(element).css('-webkit-transform');哪个回归matrix(scaleX,0,0,scaleY,0,0);有没有办法获得scaleX而且scaleY只有?
我无法获得图像的尺寸。这是代码...
HTML:
<img class="edit-img about-img" src="images/box-model.jpg">
Run Code Online (Sandbox Code Playgroud)
JavaScript:
function getDimension () {
var img = document.getElementsByClassName('about-img');
var width = img.clientWidth;
var height = img.clientHeight;
}
window.onload = getDimension;
Run Code Online (Sandbox Code Playgroud)
它说的是变量“宽度”和“高度”未定义。我也尝试使用img.width&img.height。