我正在尝试创建一个基于文件夹的网站与一堆浮动的动态陈旧图像,到目前为止,我已经使它通过jQuery和css的铬和火狐(最新发布的anno。2012年)
我的问题是(和往常一样)IE7-8-9,我不能理解在这个平台上什么可能会破坏它,我最好的猜测是这是一个jQuery交叉问题?
check this jsFiddel
or check my online exampel here
我正在寻找的是一些关于我可能会出错的建议,因为我现在头发花白,试图自己找出答案,任何建议,想法,文章等都非常受欢迎。
提前感谢Mads
jQuery代码:
$(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%");
}
});
}发布于 2013-04-03 23:02:43
试一试:
...
var box = $(this).parent(".box");
var maxWidth = box.width();
var maxHeight = box.height();
...同样宽度的plottingData,你也必须在那里迭代。你能告诉我你得到的所有盒子和图片的高度吗?你只是幸运,它们看起来都是一样的大小。将规则应用于每个框和图像。
https://stackoverflow.com/questions/15790614
复制相似问题