我只是想知道,我可以在将图像显示在网络上之前检测其属性吗?就我而言,我有一千张照片。我想在我的网页上显示它们,但有些照片的方向不同(如横向和纵向)。
我可以在图像显示在我的网页上之前检测图像的宽度和高度吗?
也许使用 JavaScript,例如:
If height>width than rotate
else just display.
是否有任何 JavaScript 函数可以做到这一点?只是为了获取不显示它的属性。有诀窍吗?
我只是想知道,我可以在将图像显示在网络上之前检测其属性吗?就我而言,我有一千张照片。我想在我的网页上显示它们,但有些照片的方向不同(如横向和纵向)。
我可以在图像显示在我的网页上之前检测图像的宽度和高度吗?
也许使用 JavaScript,例如:
If height>width than rotate
else just display.
是否有任何 JavaScript 函数可以做到这一点?只是为了获取不显示它的属性。有诀窍吗?
你必须等到它被加载。
setInterval(function () {
if(loaded)
{
clearInterval(wait);
}
else
{
log(img.width, 'x', img.height);
}
}, 0);
我在这里找到了一个示例。
希望能帮助到你。
当您的页面加载时,您可以控制每个<img/>
//function rotation
jQuery.fn.rotate = function(degrees) {
$(this).css({'-webkit-transform' : 'rotate('+ degrees +'deg)',
'-moz-transform' : 'rotate('+ degrees +'deg)',
'-ms-transform' : 'rotate('+ degrees +'deg)',
'transform' : 'rotate('+ degrees +'deg)'});
};
// When your page is loading
$( window ).load(function() {
// Each image, you can change selector
$('img').each(function(){
if(this.height() < this.width()){ // Size control
$(this).rotate(90); // rotation function call with the angle in degrees
}
});
});