开发者

Fixed floating element-adding animation to addclass

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');
      }
    });
  }  
});


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> 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜