admin管理员组

文章数量:1332628

Does anyone know what javascript effects are being used to create the navbar effect on lesscss where the navbar only bees fixed to the top after scrolling beyond a certain point. If anyone has actual code examples, or links to tutorials, that'd be appreciated.

Does anyone know what javascript effects are being used to create the navbar effect on lesscss where the navbar only bees fixed to the top after scrolling beyond a certain point. If anyone has actual code examples, or links to tutorials, that'd be appreciated.

Share Improve this question edited Oct 12, 2012 at 2:08 snakesNbronies asked Oct 11, 2012 at 22:27 snakesNbroniessnakesNbronies 3,9209 gold badges46 silver badges74 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 6

it's a javascript check using the window.onscroll event

in the HTML source near the top:

window.onscroll = function () {
    if (!docked && (menu.offsetTop - scrollTop() < 0)) {
      menu.style.top = 0;
      menu.style.position = 'fixed';
      menu.className = 'docked';
      docked = true;
    } else if (docked && scrollTop() <= init) {
      menu.style.position = 'absolute';
      menu.style.top = init + 'px';
      menu.className = menu.className.replace('docked', '');
      docked = false;
    }
};

本文标签: htmlJavascript fixedtop navbar only after scrollingStack Overflow