以下は、ホバー時に折りたたみdivを展開するためのコードです。div 内のハイパー リンクを複数回クリックした後、またはマウスを複数回ホバーした後、マウスを離したときに div が表示の高さに折りたたまれないことがあります。
マウスアウト時にdivのスタイルプロパティで設定された高さにdivを折りたたむ方法はありますか? 私の例のページは次のとおりです : http://apparelnbags.com:8000/showproduct2.aspx?ProductID=829
<script type='text/javascript' src='/jscripts/jquery-1.5/jquery-1.5.js'></script>
<script type="text/javascript">
$(document).ready(function () {
var divHeight;
var contentHeight ;
$('.expand').hover(function () {
divHeight = $(this).height();
contentHeight = 0;
$(this).children().each(function () {
contentHeight += $(this).height();
});
if (divHeight < contentHeight) {
$(this).animate({
height: contentHeight
}, 300);
}
}, function () {
if (divHeight < contentHeight) {
$(this).animate({
height: divHeight
}, 300);
}
});
});
</script>
Divのcssは
div.expand
{
border: 1px solid #C8C8C8;overflow-y: scroll; -ms-overflow-y:scroll;
}
部門コードは
<div class="text_theme_red_bold" style="Display:block;margin-top: 15px;width:438px">Active Colors:<br/>
<div id="Color_Active" class="expand" style="Display:block;margin-top: 8px;padding:5px 0px 5px 5px; height:36px;">
(!Dynamic_Contents!)
</div>
</div>