js 滚动条往下滚动时自动切换菜单栏按钮
来源:互联网 发布:创显 班班通教学软件 编辑:程序博客网 时间:2024/05/21 11:35
<!DOCTYPE html><html><head><meta charset="utf-8"><title></title><link rel="stylesheet" type="text/css" href="css/index.css"></head><style type="text/css">*{padding: 0;margin: 0;}.wrap{width: 100%;height: 50px;position: fixed;top: 0;left: 0;background: #FCCD09}.wrap a{color: #fff;line-height: 50px;margin: 0 30px;float: left;transition: .2s;padding: 0 5px}.wrap .xuan{color: #ff0000}.full{width: 100%;height: 1100px;margin-top: 50px;color: #fff;text-align: center;font-size: 300px}</style><body><div class="wrap"><li class=""><a href="#a" class="xuan">A</a></li><li class=""><a href="#b">B</a></li><li class=""><a href="#c">C</a></li><li class=""><a href="#d">D</a></li></div><div class="full" id="a" style="background: #000">#A</div><div class="full" id="b" style="background: #ffc99f">#B</div><div class="full" id="c" style="background: #ff0000">#C</div><div class="full" id="d" style="background: #ccb">#D</div><script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script><script type="text/javascript">var fulla = $("#a").offset().top;var fullb = $("#b").offset().top;var fullc = $("#c").offset().top;var fulld = $("#d").offset().top;var index;function scr(index){$(".wrap li a").removeClass("xuan").eq(index).addClass("xuan")}$(window).scroll(function(){var scrTop = $(window).scrollTop()+fulla+1;scrTop > fulla && scrTop < fullb ? scr(0):(scrTop > fullb && scrTop < fullc ? scr(1):scrTop > fullc && scrTop < fulld?scr(2):scr(3)); // 下面是上面的意思// if(scrTop > fulla && scrTop < fullb){// scr(0)// }else if(scrTop > fullb && scrTop < fullc){// scr(1)// }else if(scrTop > fullc && scrTop < fulld){// scr(2)// }else{// scr(3)// }})$('a[href^="#"]').click(function(e){ e.preventDefault(); $('html, body').animate({scrollTop: $(this.hash).offset().top}, 300); });</script></body></html>
阅读全文
0 0
- js 滚动条往下滚动时自动切换菜单栏按钮
- jquery实现浏览器滚动条往下时自动加载数据
- jquery实现浏览器滚动条往下时自动加载数据
- 原生js实现随着滚动条滚动,导航会自动切换的效果
- 往下拖动页面滚动条时,固定住菜单栏(不随其他内容网上滚动,兼容各版本IE、Chrome、Firefox)
- 往下拖动页面滚动条时,固定住菜单栏(不随其他内容网上滚动,兼容各版本IE、Chrome、Firefox)
- JS控制滚动条的位置 JS控制TextArea滚动条自动滚动到最下部
- JS Datatables超出自动添加滚动条
- 按钮代替滚动条
- 全屏页面往下往上滚动切换页面
- js控制”回到顶部“按钮滚动一屏后再显示和滚动条平滑滚动
- 如何设置VC Edit控件的编辑框滚动条自动往下滚
- 实现点击按钮,滚动条滚动
- C# TreeView实现拖动节点时滚动条自动滚动
- js控制滚动条
- js滚动条
- js滚动条技巧
- 关于js滚动条
- eclipse导入spring源码
- 死锁实例及避免策略
- android笔记:android 打包butterknife报错
- Java并发编程:CountDownLatch、CyclicBarrier和Semaphore
- Nginx配置文件中指令的作用注释
- js 滚动条往下滚动时自动切换菜单栏按钮
- 关于字符串的一些操作
- python画图:线条和颜色
- [js高手之路] es6系列教程
- Struts2框架得不到前端传过来的用户名eName
- 【动态规划】矩阵连乘问题
- textview左右滚动
- 函数sync fsync fdatasync
- linux下的退格键小研究(补充)