There are way to fixed div
Jquery!
jQuery(function($) {
function fixDiv() {
var $cache = $(‘#fixed_top’);
if ($(window).scrollTop() > 100)
$cache.css({
‘position’: ‘fixed’,
‘top’: ’10px’
});
else
$cache.css({
‘position’: ‘relative’,
‘top’: ‘auto’
});
}
$(window).scroll(fixDiv);
fixDiv();
});
CSS!
body {
height: 2500px;
padding-top: 100px;
}
#fixed_top {
color: #3e8464;
font: bold 15px arial;
padding: 10px;
margin: 10px;
border: 2px solid #22e4c0;
width: 200px;
}
HTML!
<script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js”></script>
<div id=”fixed_top”>This div is going to be fixed</div>
Question and answer is powered by AnsPress.io