0

I have a problem with this small code:

<script type='text/javascript'>

var mn = $(".stickyad");

  $(window).scroll(function () {
    if( $(this).scrollTop() > 250 ) {
      mn.addClass("stickyad-fixed");
    } else {
      mn.removeClass("stickyad-fixed");
    }
  });
</script>

the Bar is sticky at the level of 250. but I want to disable this option when it gets the bottom of the page or 600. just like in this blog: https://cleanblog-codiblog.blogspot.com/

I found this code:

$(document).ready(function() {
$(window).scroll(function () { 

console.log($(window).scrollTop());

if ($(window).scrollTop() > 250) {
  $('#stickyad').addClass('stickyad-fixed');
}

if ($(window).scrollTop() > 600) {
  $('#stickyad').removeClass('stickyad-fixed');
}
  });
});

But the problem is when I go back to top the Bar stays fixed

Thank you very much

mehulmpt
  • 15,861
  • 12
  • 48
  • 88
  • 1
    Possible duplicate of [How to create a sticky navigation bar that becomes fixed to the top after scrolling](http://stackoverflow.com/questions/14667829/how-to-create-a-sticky-navigation-bar-that-becomes-fixed-to-the-top-after-scroll) – Durga May 14 '17 at 12:54
  • I am sorryit is not just to make ti fixed. But I want to disable that option of fixation at a certain poin. – user5605193 May 14 '17 at 13:15
  • @user5605193 Is it possible for you to make an example in jsfiddle.net or something like that? I am kinda confused with what the problem is. – kucing_terbang May 14 '17 at 13:59

1 Answers1

0
if ($(window).scrollTop() > 600 || !$(window).scrollTop()) {
  $('#stickyad').removeClass('stickyad-fixed');
}
Valera Checha
  • 294
  • 4
  • 16