最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Javascript fixed-top navbar only after scrolling - Stack Overflow

programmeradmin3浏览0评论

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;
    }
};
发布评论

评论列表(0)

  1. 暂无评论