我有一个奇怪的问题。感谢克里斯 css-tricks.com,我正在使用 CSS Anything slider 我正在使用 jQuery 提取要在 slider 中显示的图像的 XML 提要:
$.post('feedURL', {},function(data){
var slides = $(data).find('slides');
for(var i = slides.length -1;i>=0;i--){
var obj = $(slides[i]);
var image = obj.find('ImageURL').text();
var str = ' <li>';
str += ' <img src="'+ image +'" />';
str += ' </li>';
$(str).find('img').one('load complete', function() {
imageResize();
}).end().appendTo($("#slider")); // Slider is a UL element on the page
}
});
图像加载后,我运行图像调整功能。我的图像以各种不同的尺寸随机上传,这就是调整大小功能的原因。
function imageResize() {
// Create the correct aspec ratio for images that are too large.
$('#slider li img').each(function() {
var maxWidth = 417; // Max width for the image
var maxHeight = 313; // Max height for the image
var ratio = 0; // Used for aspect ratio
var width = $(this).width(); // Current image width
var height = $(this).height(); // Current image height
// Check if the current width is larger than the max
if(width > maxWidth){
ratio = maxWidth / width; // get ratio for scaling image
$(this).css("width", maxWidth); // Set new width
$(this).css("height", height * ratio).css("margin-top", (maxHeight - height * ratio) / 2); // Scale height based on ratio
height = height * ratio; // Reset height to match scaled image
width = width * ratio; // Reset width to match scaled image
}
// Check if current height is larger than max
if(height > maxHeight){
ratio = maxHeight / height; // get ratio for scaling image
$(this).css("height", maxHeight); // Set new height
$(this).css("width", width * ratio).css("margin-top", "0"); // Scale width based on ratio
width = width * ratio; // Reset width to match scaled image
}
});
}
我的 Feed 中的图片加载正常,但是有些图片旋转到了一边。
这是奇怪的部分。当您查看 Feed 中的图像 URL 并将其显示在新窗口中时,Feed 中的实际图像会在其一侧旋转,但它仅在浏览器 Chrome 和 Firefox 中旋转,但NOT 在 Safari 中旋转。无论浏览器如何,在实际幻灯片中它们总是旋转到一边。
如果我右键单击并将 Feed 中的图像保存到我的桌面,图像将以正面朝上的方式保存并且不旋转。
世界上发生了什么事?有人知道吗?
最佳答案
我在提要中获取的是图像文件中的元数据。一旦我拍摄了照片文件,将其旋转了几次,然后将其旋转回正常状态并保存,它就开始显示在我的动态中。
关于jquery - Feed 图像显示在某些浏览器中旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12588832/