jQuery实现的监听导航滚动置顶状态功能示例
网络编程 2021-07-04 16:46www.168986.cn编程入门
这篇文章主要介绍了jQuery实现的监听导航滚动置顶状态功能,涉及基于jQuery的事件响应及状态监听等相关操作技巧,需要的朋友可以参考下
本文实例讲述了jQuery实现的监听导航滚动置顶状态功能。分享给大家供大家参考,具体如下
1. js代码
/ Created by EDUASK on 2016/5/20. / $(function(){ //引入id标签; var navtive=$("#native"); //设置导航标签为置顶; var offsetTop=navtive.offset().; //定义一个监听高度; var scrollHeight=$(document).scrollTop; fn(navtive,offsetTop); //设置监听事件; $(window).scroll(function(){ fn(navtive,offsetTop); }); //调用方法; function fn(navtive,offsetTop){ var scrollHeight=$(document).scrollTop(); if(offsetTop>scrollHeight){ navtive.css("",offsetTop); }else{ navtive.css("",scrollHeight); } } });
2. html代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>监听导航滚动置顶</title> <!--css样式;--> <style type="text/css"> /添加导航条的样式; / #native{ background: blue; width: 100%; height: 20px; color: red; position: absolute; : 100px; left: 0; text-align: center; } </style> <script src="http://libs.baidu./jquery/2.0.0/jquery.min.js"></script> <script type="text/javascript" src="监听导航滚动置顶.js"> </script> </head> <body> <p id="">ddddd</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <div id="native">欢迎访问我的导航条</div> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <a href="#" rel="external nofollow" >回到顶部</a> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> <p>aaaaaaaaaaaa</p> </body> </html>
感兴趣的朋友可以使用在线HTML/CSS/JavaScript代码运行工具测试运行效果。
更多关于jQuery相关内容感兴趣的读者可查看本站专题《》、《》、《》、《》、《》及《》
希望本文所述对大家jQuery程序设计有所帮助。
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程