【发布时间】:2020-11-23 16:03:24
【问题描述】:
我正在尝试重做that example 作为练习。
当我点击上面或下面的文本时,我试图让图像 div 动态重新调整。
所以我画了一个草图来试试。但是我被卡住了,因为当 div expanded 打开时我不知道如何计算剩余空间,因此图像适合该空间。
jQuery(document).ready(function($)
{
$("#ex").click(function()
{
$("#expanded").slideToggle(200)
if ($("#ex").text() == "infos")
{
$("#ex").html("close")
$("#fit-picture").css("height", "20px");
}
else
{
$("#ex").text("infos")
$("#fit-picture").css("height", "100vh");
}
});
});
body{margin:0}
.container{
height: 100%;
min-height: 100%;}
#expanded{
margin-top: 0px;
background: gray;
width: 50vw; height: 50vh;
}
#ex {
display: block;
width: 50vw;
background-color:darkgrey;
text-decoration:none;
}
#ex:hover {
background:black;
}
.container{
height:100vh;
}
#fit-picture{
width: auto;
height: 100vh;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class ="container">
<div class="expand">
<a href="#" id="ex">infos</a>
</div>
<div id="expanded" style="display: none;">the image is supposed to be reduced proportionally to fit the remaining space of the screen.
</div>
<img id="fit-picture"
src="https://www.wanimo.com/veterinaire/wp-content/uploads/2018/11/chat-jaloux-e1574672723199@2x.jpg">
</div>
【问题讨论】:
标签: html jquery css responsive-design