如何在显示后将元素粘贴在页面上(位置:固定)?
我正在为我的网站开发类似通知的咆哮,目前是这样的:
HTML:
<div id="growls"></div>
CSS:
#growls {
position: fixed;
right: 20px;
bottom: 20px;
}
.growl {
display: none;
}
JS:
function growl(message) {
if (growls < 5) {
growls = growls + 1;
$('<div class="growl short block">' + message + '</div>').prependTo('#growls').fadeIn('slow').delay(2000).fadeOut('slow', function() { growls = growls - 1 });
}
}
它基本上将新的“咆哮”放在现有的“咆哮”之上,问题是,当旧的“咆哮”消失时,新的“咆哮”突然崩溃,如果您正在阅读消息,这会非常烦人。
我正在考虑让新的咆哮 div 位置在显示后固定,但它不是很干净(大量添加和减去元素偏移)
有没有更好的方法来做到这一点?
I'm developing a growl like notifications for my site, currently it's like this:
HTML:
<div id="growls"></div>
CSS:
#growls {
position: fixed;
right: 20px;
bottom: 20px;
}
.growl {
display: none;
}
JS:
function growl(message) {
if (growls < 5) {
growls = growls + 1;
$('<div class="growl short block">' + message + '</div>').prependTo('#growls').fadeIn('slow').delay(2000).fadeOut('slow', function() { growls = growls - 1 });
}
}
It basically put new 'growl' on top of existing ones, problem is, when old ones disappear, new 'growls' suddenly collapse down, very annoying if you are reading the message.
I'm thinking about making the new growl div position fixed after it display, but it's not very clean (tons of adding and subtracting from elements offset)
Is there any better way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道它没有回答所提出的确切问题,但我的建议是使用
slideUp
来隐藏元素,而不是fadeOut
。这将为其他元素移动到新位置提供良好的流畅运动。这样读者的眼睛很容易跟随,不会导致元素跳跃。或者为了获得更好的外观,请使用
animate
并对高度和不透明度进行动画处理:http:// /jsbin.com/exonal/4
I know it doesn't answer the exact question asked, but my suggestion would be to use
slideUp
to hide the elements instead offadeOut
. This will give a nice fluid movement for the other elements to move into their new position. This can easily be followed by the readers eye and won't cause the elements to jump.Or for an even nicer look, use
animate
and animate the height and the opacity:http://jsbin.com/exonal/4