2 回答
TA贡献1843条经验 获得超7个赞
这里有一个例子供你尝试,希望这有帮助
$('body').on("click", '.step2-opt', function () {
// get the height of step2info
var height = $('.step2info').css("height");
// set the height of quiz__drawer
$('.quiz__drawer').css("height", height)
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="step2info" style="height: 200px; width: 200px; background-color: red;"></div>
<div class="quiz__drawer" style="height: 100px; width: 200px; background-color: green;"></div>
<button class="step2-opt">set height</button>
TA贡献1853条经验 获得超9个赞
如您所见,此功能在单击第一个div后均衡高度:
$.fn.equalizeHeights = function(){
return this.height( Math.max.apply(this, $(this).map(function(i,e){ return $(e).height() }).get() ) )
}
function test(){
$('.step2info, .quiz__drawer').equalizeHeights();
}
<script
src="https://code.jquery.com/jquery-3.5.1.js"
integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc="
crossorigin="anonymous"></script>
<body>
<div class="step2info" onclick="test()">dkdpodkds<br>soskdsopkdspodskpskpkpk<br>sopkspokdspskposkspksapk<br></div>
<div class="quiz__drawer"></div>
</body>
添加回答
举报