I have div
that I would like it to hold at the top when the div has to play at the top. I tried to this , but resulted in% blinking%%. What's wrong?
SCRIPT
$(window).on('scroll', function() {
var ell = $('.menu').offset().top;
var ill = $(document).scrollTop();
var screen = $(window).height();
var distance = ell - ill;
if(ell < ill ) {
$('.menu').css("position", "fixed");
$('.menu').css("top", "0");
}else{
$('.menu').css("position", "relative");
$('.menu').css("top", "initial");
}
});
UPDATE
I discovered the problem, since the div
is div
, will be the same distance from the top as the scroll, so it will always be stuck to the top. Is there a way to save the old position?