jquery - Feed 图像显示在某些浏览器中旋转

标签 jquery css xml image

我有一个奇怪的问题。感谢克里斯 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/

相关文章:

javascript - 如何在不提交表单的情况下通过按键盘上的 Enter 来获取文本值

jquery - 获取页面上未选中单选按钮的问题列表 JQuery

jQuery AJAX 返回 200 OK 状态,但有错误。如何查看错误的详细信息?

html - CSS3 根据屏幕大小/显示重新调整页面大小

css - 使用 css/sass 缩放 Sprite

python - 按标签用python对xml进行排序

javascript - 按数据属性查找和删除项目

javascript - JQuery UI 对话框可以记住它在打开和关闭之间的位置吗

android - 按钮总是以状态列表中第一个列出的样式显示,无论其状态如何

json - 用于在服务器上存储文章的 XML、JSON、YAML 或 CSV?