jquery - 粘性导航栏 onScroll?

标签 jquery html css twitter-bootstrap navbar

我目前正在为自己构建一个网站,我发现在导航栏位于图像下方的多个网站上,这种效果非常棒,但当您滚动经过它时,它会粘在顶部。

Example

我怎样才能做到这一点?另外,我怎样才能达到类似于 this website with a similar navbar style 上的效果? ?

最佳答案

这是@Matthew 所说的内容:

检查这个 fiddle http://jsfiddle.net/luckmattos/yp8HK/1/

JQUERY

var num = 200; //number of pixels before modifying styles

$(window).bind('scroll', function () {
    if ($(window).scrollTop() > num) {
        $('.menu').addClass('fixed');
    } else {
        $('.menu').removeClass('fixed');
    }
});

希望对您有所帮助,我使用的是 bootstrap 导航栏。

关于jquery - 粘性导航栏 onScroll?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22541364/

相关文章:

jquery - Bootstrap 轮播 slider 不会等到下一个图像加载成功

jquery - 使用 jQuery 清除焦点上的输入并返回模糊

javascript - 使用 jQuery 和 for 循环 JavaScript 创建 html 元素

html - d3 节点标记

javascript - Bootstrap 下拉菜单无法正常工作

jQuery——从 json 中填充选择

javascript - 按键时更改图像

javascript - 文件读取器在 Chrome 中不工作

javascript - 从 HTML header VS JS 文件 VS Vue 组件导入 CSS 的区别

css - ASP.NET MVC3-Site.css