小智 25
您可以简单地比较图像的宽度和高度.
var someImg = $("#someId");
if (someImg.width() > someImg.height()){
//it's a landscape
} else if (someImg.width() < someImg.height()){
//it's a portrait
} else {
//image width and height are equal, therefore it is square.
}
Run Code Online (Sandbox Code Playgroud)
这对我有用,使用自然高度/宽度来获取原始属性。
function imageOrientation(src) {
var orientation,
img = new Image();
img.src = src;
if (img.naturalWidth > img.naturalHeight) {
orientation = 'landscape';
} else if (img.naturalWidth < img.naturalHeight) {
orientation = 'portrait';
} else {
orientation = 'even';
}
return orientation;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17786 次 |
| 最近记录: |