首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >关于jQuery / Css 7-8-9问题的建议

关于jQuery / Css 7-8-9问题的建议
EN

Stack Overflow用户
提问于 2013-04-03 22:47:42
回答 1查看 121关注 0票数 0

我正在尝试创建一个基于文件夹的网站与一堆浮动的动态陈旧图像,到目前为止,我已经使它通过jQuery和css的铬和火狐(最新发布的anno。2012年)

我的问题是(和往常一样)IE7-8-9,我不能理解在这个平台上什么可能会破坏它,我最好的猜测是这是一个jQuery交叉问题?

check this jsFiddel

or check my online exampel here

我正在寻找的是一些关于我可能会出错的建议,因为我现在头发花白,试图自己找出答案,任何建议,想法,文章等都非常受欢迎。

提前感谢Mads

jQuery代码:

代码语言:javascript
复制
$(window).load(function () {
    plottingData();
    resizeImage();
});

$(window).resize(function () {
    plottingData();
    resizeImage();
});

function plottingData() {
    var image = $('.box img');
    var divW = $(".box").width();
    var divH = $(".box").height();
    var imgW = image.width();
    var imgH = image.height();
    $('.outputText').html('DIV CONTAINER W: ' + divW + ' H: ' + divH + '  ::  imgW: ' + imgW + ' : imgH: ' + imgH);
}


function resizeImage() {
    $("img").each(function () {
        var maxWidth = $(".box").width();; // Max width for the image
        var maxHeight = $(".box").height();; // Max height for the image
        var maxratio = maxHeight / maxWidth;
        var width = $(this).width(); // Current image width
        var height = $(this).height(); // Current image height
        var curentratio = height / width;
        // Check if the current width is larger than the max

        if (curentratio > maxratio) {
            ratio = maxWidth / width; // get ratio for scaling image
            /*
            $(this).css("width", maxWidth); // Set new width
            $(this).css("height", height *ratio); // Scale height based on ratio
            */
            $(this).css("width", "100%");
            $(this).css("height", "auto");
        } else {
            /*
            ratio = maxHeight / height; // get ratio for scaling image
            $(this).css("height", maxHeight);   // Set new height
            $(this).css("width", width * ratio);    // Scale width based on ratio
            */
            $(this).css("width", "auto");
            $(this).css("height", "100%");
        }

    });
}
EN

回答 1

Stack Overflow用户

发布于 2013-04-03 23:02:43

试一试:

代码语言:javascript
复制
...
var box = $(this).parent(".box");
var maxWidth = box.width();
var maxHeight = box.height();
...

同样宽度的plottingData,你也必须在那里迭代。你能告诉我你得到的所有盒子和图片的高度吗?你只是幸运,它们看起来都是一样的大小。将规则应用于每个框和图像。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15790614

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档