jQuery/ついてくるサイドメニュー

jQuery
$(function(){
  var navi = $('.fixnav');
  var main  = $('.main');
  var target_top = navi.offset().top - parseInt(navi.css('margin-top'), 10);
  var sub_top = main.offset().top - parseInt(main.css('margin-top'), 10);
  var sub_scroll = main.offset().top + main.outerHeight(true)
  					 - navi.outerHeight(true) 
  					 - parseInt(navi.css('margin-top'), 10);

  if (navi.outerHeight(true) + target_top < main.outerHeight(true) + sub_top) {
    $(window).scroll(function () {
      var ws = $(window).scrollTop();
      if (ws > sub_scroll) {
        navi.css({
        	position:'fixed',
        	top: sub_scroll - ws + 'px'
        });
      } else if(ws > target_top) {
        navi.css({position:'fixed', top: '0px'});
      } else {
        navi.css({position:'relative', top: '0px'});
      }
    });
  }
});

menu1

  • Sweb
  • CSS
  • JS
  • Contact
  • Business