1
When I scroll down, the div#chat, is fixed everything straight. However the problem is that the layout breaks losing the right margin. How can I solve 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>
<div style="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>
Failed to add CSS for f-Nav, there is no position: Fixed in the code you posted.
– Guilherme Nascimento
Hello @Guilhermenascimento ! really was missing. Now I’ve updated the code thanks for warning.
– alexander Pataki