Javascript固定顶部navbar只有滚动后 [英] Javascript fixed-top navbar only after scrolling

查看:187
本文介绍了Javascript固定顶部navbar只有滚动后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道使用什么JavaScript效果在 lesscss.org 上创建导航栏效果其中导航栏仅在滚动超过某一点之后才固定到顶部。

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

推荐答案

这是一个javascript检查使用<在顶部附近的HTML源代码中的code> window.onscroll 事件

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

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

这篇关于Javascript固定顶部navbar只有滚动后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆