[英]Make span heights equal to its parent div's height
I want to change an element's height to make it match its parent's: 我想更改元素的高度以使其与其父元素的高度匹配:
<div id="div-login-msg" class="alert">
<div id="icon-login-msg" class="glyphicon glyphicon-chevron-right"></div>
<span id="text-login-msg">Some message</span>
</div>
#icon-login-msg
{
width: 30px;
float: left;
line-height: 28px;
text-align: center;
background-color: #dadfe1;
margin-right: 5px;
transition: all ease-in-out 500ms;
}
text-login-msg changes when the form is POSTed through AJAX: 通过AJAX发布表单时,text-login-msg会更改:
fadeMessage: function ($msgId, $msgText, $divTag, $iconTag)
{
var $msgAnimateTime = 150;
$msgId.fadeOut($msgAnimateTime, function ()
{
$(this).text($msgText).fadeIn($msgAnimateTime, function ()
{
$iconTag.height($divTag.height()); // line I'm interested in
});
});
},
changeMessage: function ($divTag, $iconTag, $textTag, $divClass, $msgText)
{
var $msgShowTime = 5000;
var $msgOld = $divTag.text();
MyNamespace.fadeMessage($textTag, $msgText, $divTag, $iconTag);
$divTag.addClass($divClass);
setTimeout(function ()
{
MyNamespace.fadeMessage($textTag, $msgOld, $divTag, $iconTag);
$divTag.removeClass($divClass);
}, $msgShowTime);
}
How could I change the mentioned line so that when the fade animation completes, $iconTag changes immediatly to $divTag.height? 如何更改提到的行,以便在淡入淡出动画完成时,$ iconTag立即更改为$ divTag.height? Using it as shown is way too slow.
如图所示使用它太慢了。
Basically, what I want is $divTag.height === $iconTag.height
基本上,我想要的是
$divTag.height === $iconTag.height
What about? 关于什么?
#text-login-msg {
display: block;
height: 100%;
}
I ended up adding this: 我最终添加了这个:
#text-login-msg
{
display: flex;
}
And changing how the message is displayed to: 并将消息的显示方式更改为:
fadeMessage: function ($msgId, $msgText, $divTag, $iconTag)
{
$msgId.text($msgText);
$iconTag.css("line-height", $divTag.height() + "px");
},
The animation provided by transition: all ease-in-out
alone is better than the kind of laggy animation done by .fadeIn
and .fadeOut
transition: all ease-in-out
提供的动画transition: all ease-in-out
单独使用transition: all ease-in-out
动画要好于.fadeIn
和.fadeOut
完成的.fadeIn
.fadeOut
动画
See updated fiddle 查看更新的小提琴
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.