【发布时间】:2016-10-17 17:25:27
【问题描述】:
所以我有一个 php 脚本来从重复以下 HTML 的数据库中生成新闻/案例帖子
<a href='/post/placeholder'>
<div class='col nopadding col12-12 counter'>
<div class='col col6-12 vheight'>
<h2>placeholder</h2>
<p>placeholder</p>
</div>
<div class='col col6-12 nopadding varheight '>
<div class='imagewrapper'>
<img src='/public/images/images/placeholder.jpg' />
</div>
</div>
</div>
</a>
我想选择每个“计数器”类,并将 .vheight 的高度存储在一个变量中,以便 .varheight(图像)响应时始终保持相同的高度。
我目前有这个 JQuery
$(window).resize(function () {
$( ".counter" ).each(function() {
var $counter = $(this).next('.vheight').outerHeight(true);
$(this).next(".varheight").css("height", $counter);
});
});
$(window).load(function () {
$( ".counter" ).each(function() {
var $counter = $(this).next('.vheight').outerHeight(true);
$(".varheight").css("height", $counter);
});
});
我似乎无法让它工作,并查看了关于 SO 的其他类似答案。
这是测试开发链接,您可以查看它的外观
【问题讨论】:
-
我认为你应该使用
.find('.vheight')而不是.next('.vheight'),因为.vheight是.counter的孩子
标签: javascript jquery html height responsive