如何使用 JavaScript 在 Web 中显示之前旋转图像
How to Rotate image before displaying in web using 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
}
});
});
相关文章:
- 全屏背景图像+旋转图像
- 每次单击JQuery时旋转图像
- 旋转和取消旋转图像单击与 javascript
- SVG具有旋转图像的低性能
- 旋转图像,使其看起来像在旋转
- 向下滑动时旋转图像
- 滚动时旋转图像
- 使用 kineticjs 如何就地旋转图像对象
- 将变量 javascript 添加到用于旋转图像的链接中
- 旋转图像w/jQuery..但是调整大小不起作用
- 使用 JQueryRotate 逆时针旋转图像
- 在不旋转元素尺寸的情况下旋转图像
- 如何旋转图像并保存图像
- 在HTML5画布中,有没有办法以不同的角度旋转图像
- 在 html5 画布中用鼠标旋转图像
- 如何在时间变化时旋转图像
- 在横幅中水平对齐图像和 JavaScript 旋转图像
- 在 HTML 中旋转图像
- 如何使用 JavaScript 在 Web 中显示之前旋转图像
- jQuery - 旋转图像