我在重新调整大小时使用 Jquery 来保持我的纵横比。在小屏幕上,我想在不同的类上使用这个脚本。这一切似乎在第一次加载时工作得很好。
但是,当我将窗口大小从 > 768 调整为小于 < 767 时,除非我重新加载,否则脚本将无法工作。奇怪的是,当我在一个 <767 的小窗口中加载网站并将其调整为 >768 的大窗口时,脚本确实可以工作,并且在重新调整大小时会继续工作。知道如何解决这个问题吗?
if ($(window).width() > 768) {
/* square featured-column1 box aanpassing */
equalheight = function(container) {
var currentTallest = 0,
currentRowStart = 0,
rowDivs = new Array(),
$el,
topPosition = 0;
$(container).each(function() {
$el = $(this);
$($el).height('auto')
topPostion = $el.position().top;
if (currentRowStart != topPostion) {
for (currentDiv = 0; currentDiv < rowDivs.length; currentDiv++) {
rowDivs[currentDiv].height(currentTallest);
}
rowDivs.length = 0; // empty the array
currentRowStart = topPostion;
currentTallest = $el.height();
rowDivs.push($el);
} else {
rowDivs.push($el);
currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest);
}
for (currentDiv = 0; currentDiv < rowDivs.length; currentDiv++) {
rowDivs[currentDiv].height(currentTallest);
}
});
}
$(window).load(function() {
equalheight('.featured-column');
});
$(window).resize(function() {
equalheight('.featured-column');
});
/* Aspect ratio box (responsive rechthoek) aanpassing */
$(document).ready(function() {
aspectResize();
$(window).resize(aspectResize);
});
aspectResize = function() {
var $aspect = $('div.up-to-date-bar');
var width = $aspect.width();
$aspect.height(width / 3 * 1);
}
}
/* Aspect ratio box (responsive rechthoek) aanpassing up-to-date-column*/
if ($(window).width() < 767) {
$(document).ready(function() {
aspectResize();
$(window).resize(aspectResize);
});
aspectResize = function() {
var $aspect = $('div.up-to-date-column');
var width = $aspect.width();
$aspect.height(width / 1 * 1);
}
}