我遇到了一个jQuery的问题。无法想出如何解决。 我有多个高度不同的部分:
<section id="1" class="something" style="height:111px; background:red;">1</section>
<section id="2" class="something" style="height:222px; background:blue;">2</section>
<section id="3" class="something" style="height:333px; background:green;">3</section>
当窗口小于500px时,我的jQuery会缩放每个部分的高度:
var org_height = $('.something').height();
$(window).resize(function() {
$(".something").each(function() {
var win = $(window).width();
var height = $('.something').height();
if(win < 500) {
y = 500 - win;
$('.something').css("height",org_height-y/3+"px");
}
else {
$('.something').css("height",org_height+"px");
}
});
});
JSFiddle: https://jsfiddle.net/owtz31jj/
如何存储每个部分的原始高度,并根据每个高度进行缩放,然后再恢复到原始高度。我非常感谢任何帮助。
$(this)
吗?这将确保您从相应的元素获取org_height。 - Andreas Louv