滚动监听
bootstrap 的scrollspy,需要借助.nav样式,活动的部分是加
.active类。本身导航没有position:fixed,需要自己加入
滚动监听。只有滚动和监听,只有默认锚点链接做调转,若想改变,只有自己写跳转方法--
阻止a标签跳转(不直接用锚点链接做跳转);而是用animate(scrollTop)跳转,scrollTop可以设置距顶端的距离.animate({scrollTop: });
html
<div id="menu">
<div id="nav-awu">
<ul class="nav">
<!--<li><a href="#cooperation">潮童</a></li>-->
<li><a href="#downJacket" onclick="return a_stop('#downJacket');" >羽绒</a></li>
<li><a href="#cotton" onclick="return a_stop('#cotton');" >时尚棉服</a></li>
<li><a href="#sweater" onclick="return a_stop('#sweater');" >毛衣</a></li>
<li><a href="#trousers" onclick="return a_stop('#trousers');" >裤装</a></li>
<li><a href="#shoes" onclick="return a_stop('#shoes');" >鞋履</a></li>
</ul>
</div>
</div>

css 重写样式

#menu ul.nav,
#menu ul.nav:hover{border: none; background: none;height: 50px; line-height: 50px;margin:; padding:;} #menu ul.nav-tab,
#menu ul.nav-tab:hover{border: none; background: none;height:50px; line-height: 50px;margin:; padding:}
#menu ul li {
display: inline-block;
width: 16%;
margin: 10px 2% 0;
height: 30px;
/*margin: 0;*/
padding:;
border: none;
text-align: center;
} .nav > li > a {
/*position: relative;*/
display: block;
width: auto;
padding:; //默认情况下 padding有数值,需要设为0
}
#menu ul li a {
margin:;padding:;
height: 28px;
line-height: 28px;
font-size: 12px;
text-decoration: none;
color: #fff;
} /*#menu ul li a:hover{ font-size:12px; text-decoration: none; color: #fff; border-bottom:2px solid #fefb00; }*/
//active类
#menu ul li.active > a,
#menu ul li.active > a:focus{
margin:;padding:;
height: 28px;
line-height: 28px;
border:none;
border-bottom: 2px solid #fefb00;
font-size: 12px;
text-decoration: none;
color: #fff;
background: none;
/*text-decoration: dashed;*/
}
.nav > li > a:hover, .nav > li > a:focus {
text-decoration: none;
background: none;
}

js

$(function () {
//导航监控
var fixWidth = ($(window).width() - $("#menu").width()) / 2;
var scroHeight = $("#menu").offset().top;
$(window).scroll(function () {
if ($(window).scrollTop() >= scroHeight) {
$("#menu").css({
"width": $("#banner").width(),
"position": "fixed",
"top": 0,
"left": fixWidth
});
$("#box").css("margin-top","50px");
}
else {
$("#menu").css({
"position": "relative",
"top": 0,
"left": 0
});
$("#box").css("margin-top","0");
}
});
$('body').scrollspy({target: '#menu', offset: 50});//offset是根据 多少的偏移的距离 来做监听
}); function a_stop(attr){
var isRel = $("#menu").css("position") == "relative";
var fix = 50;
$("html,body").animate({scrollTop:$(attr).offset().top - fix},10);
return false; //必须要
}

 1.阻止a标签跳转
参考 http://blog.csdn.net/awe5566/article/details/22583699
href="#downJacket"  锚点链接 必须写;

但又想阻止a标签跳转(阻止默认的滚动监听,好自己设置scrollTop),
onclick="return fales"
<a href="#downJacket" onclick="return a_stop('#downJacket');" >羽绒</a>

2.自己写跳转方法 :用animate({scrollTop:number) 做跳转
scrollTop

offset是根据 多少的偏移的距离 来做监听,offset一般和导航高度有关

滚动监听: bootstrap 的scrollspy的更多相关文章

  1. Bootstrap学习js插件篇之滚动监听

    1.滚动监听 案例 滚动监听插件可以根据滚动条的位置自动更新所对应的导航标记.Bootstrap中文网左侧就是一个滚动监听的例子. 代码段: <nav id="navbar-examp ...

  2. bootstrap-js(3)滚动监听

    导航条实例 ScrollSpy插件根据滚动的位置自动更新导航条中相应的导航项. 拖动下面区域的滚动条,使其低于导航条的位置,注意观察active类的变化.下拉菜单中的子项也会跟着变为高亮状态. 1.调 ...

  3. Bootstrap滚动监听(Scrollspy)插件

    Bootstrap滚动监听(Scrollspy)插件,即自动更新导航插件,会根据滚动条的位置自动更新对应的导航目标

  4. bootstrap源码之滚动监听组件scrollspy.js详解

    其实滚动监听使用的情况还是很多的,比如导航居于右侧,当主题内容滚动某一块的时候,右侧导航对应的要高亮. 实现功能 1.当滚动区域内设置的hashkey距离顶点到有效位置时,就关联设置其导航上的指定项 ...

  5. Bootstrap滚动监听

    滚动监听(Scrollspy)插件,即自动更新导航插件,会根据滚动条的位置自动更新对应的导航目标.其基本的实现是随着您的滚动,基于滚动条的位置向导航栏添加 .active class. <!DO ...

  6. Bootstrap 下拉菜单和滚动监听插件

    一.下拉菜单 常规使用中,和组件方法一样,代码如下: //声明式用法 <div class="dropdown"> <button class="btn ...

  7. bootstrap的滚动监听

    <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8& ...

  8. Bootstrap -- 插件: 模态框、滚动监听、标签页

    Bootstrap -- 插件: 模态框.滚动监听.标签页 1. 模态框(Modal): 覆盖在父窗体上的子窗体. 使用模态框: <!DOCTYPE html> <html> ...

  9. Bootstrap-Plugin:滚动监听(Scrollspy)插件

    ylbtech-Bootstrap-Plugin:滚动监听(Scrollspy)插件 1.返回顶部 1. Bootstrap 滚动监听(Scrollspy)插件 滚动监听(Scrollspy)插件,即 ...

随机推荐

  1. sql server中Join有几种

    JOIN: 如果表中有至少一个匹配,则返回行 (也就是 inner join)LEFT JOIN: 即使右表中没有匹配,也从左表返回所有的行RIGHT JOIN: 即使左表中没有匹配,也从右表返回所有 ...

  2. jfinal的configPlugin基本配置代码

    直接上代码: public void configPlugin(Plugins me) { // 这里是在数据库的配置文件中读取数据库的一些信息 DruidPlugin dbPlugin = new ...

  3. PHP实现AOP的雏形

    AOP是OOP的延续,是Aspect Oriented Programming的缩写,意思是面向方面编程,有的又称之为面向切面编程.在企业级开发中面向方面编程很有用.比如,我们在调用某些特定的方法之前 ...

  4. Zip 压缩问题件,获取真实扩展名

    ].InputStream); foreach (var element in _ZIP.Entries) { using (System.IO.StreamReader _ddd = new Sys ...

  5. Memcache集群安装与配置

    Memcache集群的安装和配置 :http://blog.163.com/asd_wll/blog/static/210310402013084405481/

  6. offsetof宏的实现

    1.c语言的结构体中,因为字节对齐的问题,导致成员地址并不能根据类型的大小进行计算.例如: struct test { char ch; int a; } printf("test的大小=% ...

  7. C#反射取数组单个元素的类型

    去bing上查了一下,果然有和我一样蛋疼的朋友,他们在论坛研究了半天,最后还是暴力解决: public Type GetArrayElementType(Type t) { string tName ...

  8. Atitit .h5文件上传 v3

    Atitit .h5文件上传 v3 1. 上传原理1 2. V3版新特性1 3. Html1 4. Js2 5. uploadV2.js2 6. upServlet & FileUploadS ...

  9. RS232接口

    想用下板子,却发现板子和USB转串口线都是母口,无耐只能自己用线将对应的管脚连起来. 结果测试的时候发现,板子能发不能收.将板子串口的23连起来,回环正常.电脑USB转串口线上的23连起来也回环正常. ...

  10. python对象序列化之pickle

    本片文章主要是对pickle官网的阅读记录. The pickle module implements binary protocols for serializing and de-serializ ...