When I scroll down, the chat # div will get everything fixed. But the problem is that the layout breaks down the right margin. How can I resolve this problem?
$(document).ready(function() {
var nav = $('#chat');
$(window).scroll(function() {
if ($(this).scrollTop() > 300) {
nav.addClass("f-nav");
} else {
nav.removeClass("f-nav");
}
});
});
.f-nav {
z-index: 9999;
position: fixed;
top: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><divstyle="width:100%; display:flex;">
<div style="width:70%; height: 2000px; background-color: #ff9d58; margin:10px;">
</div>
<div id="chat" style="width:30%; height: 400px; background-color:#22792d; margin:10px;">
</div>
</div>