Question

I want to add a fadein effect to the menu when it changes classes to a fixed position at the top when we scroll down the page.

http://jsfiddle.net/dueWG/9/

the js:

$(function () {
  var msie6 = $.browser == 'msie' && $.browser.version < 7;
  if (!msie6) {
    var top = $('#navmenu').offset().top - parseFloat($('#navmenu').css('margin-top').replace(/auto/, 0));
    $(window).scroll(function (event) {
      var y = $(this).scrollTop();
      if (y >= top) {
        $('#navmenu').addClass('fiksed');
      } else {
        $('#navmenu').removeClass('fiksed');
      }
    });
  }  
});
Was it helpful?

Solution

is this the effect you are looking for?

http://jsfiddle.net/dueWG/10/

the code:

<script>
$(function () {

  var msie6 = $.browser == 'msie' && $.browser.version < 7;

  if (!msie6) {
    var top = $('#navmenu').offset().top - parseFloat($('#navmenu').css('margin-top').replace(/auto/, 0));
    $(window).scroll(function (event) {
      // what the y position of the scroll is
      var y = $(this).scrollTop();

      // whether that's below the form
      if (y >= top) {
        // if so, ad the fixed class
        if ( $('#navmenu').is('.fiksed') ) {
            return;
        }
        $('#navmenu').hide().addClass('fiksed').fadeIn();
    } else {
        // otherwise remove it
        $('#navmenu').removeClass('fiksed');
      }
    });
  }  
});
</script> 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top