[英]Scroll notification mesage till bottom of fixed menu
I want to scroll a notification message till bottom of top fixed menu but the body content continue to scroll and only the notification box will remain fixed to bottom of fixed top menu. 我想滚动一个通知消息,直到顶部固定菜单的底部,但是正文内容继续滚动,只有通知框将固定在顶部固定菜单的底部。 Here is a fiddle example: 这是一个小提琴示例:
html: HTML:
<div class="menu-fixed">I am a fixed menu! </div>
<div class="bodyContent">I am the body content of this page
<div class="notification">I am a notification message!
Scroll me to the bottom of top menu only! and back.</div>
</div>
css: CSS:
.menu-fixed{
position: fixed;
text-align: center;
width: 100%;
height: 100px;
border:1px solid blue;
background: rgba(0,0,0,0.3);
font-size:30px;
}
.bodyContent{
padding-top:120px;
height:1000px;
width:100%;
background:lime;
text-align: center;
font-size:50px;
}
.notification{
height: 100px;
left: 80%;
position: absolute;
width: 200px;
background: rgba(255,255,255,0.9);
font-size:20px;
}
Can anyone help me with this scrollTo function please? 有人可以帮助我使用scrollTo功能吗? ty. TY。
If I understand your question correctly, this should get you in the right direction: 如果我正确理解了您的问题,那么应该会为您提供正确的方向:
$(document).ready(function() {
$(window).scroll(function() {
var menuHeight = $(".menu-fixed").outerHeight();
var windowScrollTop = $(window).scrollTop();
if (windowScrollTop > 80) {
$(".notification").css({ top: windowScrollTop + menuHeight });
}
else {
$(".notification").css({ top: 'auto' });
}
});
});
I've updated your JSFiddle: http://jsfiddle.net/VPzxG/1823/ 我已经更新了您的JSFiddle: http : //jsfiddle.net/VPzxG/1823/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.