jquery实现滚动下拉标题浮动固定显示
来源:互联网 发布:传奇数据库增加新的怪 编辑:程序博客网 时间:2024/06/05 14:53
利用jquery来实现滚动下拉标题浮动固定显示
<div class="article_manage clearfix"> <div class="article_r"> <span class="link_postdate">2015-11-04 18:32</span> <span class="link_view" title="阅读次数">1596人阅读</span> <span class="link_comments" title="评论次数"> <a href="#comments" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_pinglun'])">评论</a>(0)</span> <span class="link_collect tracking-ad" data-mod="popu_171"> <a href="javascript:void(0);" onclick="javascript:collectArticle('asp.net%e5%bc%80%e5%8f%91%e4%b8%ad%e5%88%a9%e7%94%a8jquery%e6%9d%a5%e5%ae%9e%e7%8e%b0%e6%bb%9a%e5%8a%a8%e4%b8%8b%e6%8b%89%e6%a0%87%e9%a2%98%e6%b5%ae%e5%8a%a8%e5%9b%ba%e5%ae%9a%e6%98%be%e7%a4%ba','49641605');return false;" title="收藏">收藏</a></span> <span class="link_report"> <a href="#report" onclick="javascript:report(49641605,2);return false;" title="举报">举报</a></span> </div></div> <style type="text/css"> .embody{ padding:10px 10px 10px; margin:0 -20px; border-bottom:solid 1px #ededed; } .embody_b{ margin:0 ; padding:10px 0; } .embody .embody_t,.embody .embody_c{ display: inline-block; margin-right:10px; } .embody_t{ font-size: 12px; color:#999; } .embody_c{ font-size: 12px; } .embody_c img,.embody_c em{ display: inline-block; vertical-align: middle; } .embody_c img{ width:30px; height:30px; } .embody_c em{ margin: 0 20px 0 10px; color:#333; font-style: normal; }</style><script type="text/javascript"> $(function () { try { var lib = eval("("+$("#lib").attr("value")+")"); var html = ""; if (lib.err == 0) { $.each(lib.data, function (i) { var obj = lib.data[i]; //html += '<img src="' + obj.logo + '"/>' + obj.name + " "; html += ' <a href="' + obj.url + '" target="_blank">'; html += ' <img src="' + obj.logo + '">'; html += ' <em><b>' + obj.name + '</b></em>'; html += ' </a>'; }); if (html != "") { setTimeout(function () { $("#lib").html(html); $("#embody").show(); }, 100); } } } catch (err) { } });</script> <div class="category clearfix"> <div class="category_l"> <img src="http://static.blog.csdn.net/images/category_icon.jpg"> <span>分类:</span> </div> <div class="category_r"> <label onclick="GetCategoryArticles('571993','taomanman','top','49641605');"> <span onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_fenlei']);">C#.NET编程<em>(221)</em></span> <img class="arrow-down" src="http://static.blog.csdn.net/images/arrow_triangle _down.jpg" style="display:inline;"> <img class="arrow-up" src="http://static.blog.csdn.net/images/arrow_triangle_up.jpg" style="display:none;"> <div class="subItem"> <div class="subItem_t"><a href="http://blog.csdn.net/taomanman/article/category/571993" target="_blank">作者同类文章</a><i class="J_close">X</i></div> <ul class="subItem_l" id="top_571993"> </ul> </div> </label> </div></div> <div class="bog_copyright"> <p class="copyright_p" >版权声明:本文为博主原创文章,未经博主允许不得转载。</p> </div>
1、问题来源
在实际项目开发中,页面如果内容很多,会出现滚动条,方便向下浏览,但是页面的标题头也会随下拉操作而无法看到,那如果我们想让下拉过程中标题仍在页面最顶端固定浮动显示,我们该如何做呢?
2、解决方法
使用css进行位置控制,然后结合jquery来处理滚动事件添加样式。需要注意的是,需要固定的部分一定要设置背景颜色 background-color属性值,如果页面是白色则设置#fff,否则效果出不来。
3、示例代码
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>滚动条下拉标题固定在头部</title> <script type="text/javascript" src="../../Scripts/Jquery-1.8.0.min.js"></script> <script type="text/javascript"> window.onscroll = function () { if ($(document).scrollTop() > 0) { $(".pf").addClass('float'); } else { $(".pf").removeClass('float'); } } </script> <style type="text/css"> .pf { width: 100%; height: 50px; background-color: #494949; text-align: center; line-height: 50px; color: #fff; } html { _background-image: url(about:blank); _background-attachment: fixed; /** 防止 ie6 抖动 **/ } .float { position: fixed; z-index: 999999; top: 0px; } * html .float { position: absolute; _top: expression(documentElement.scrollTop-0); } </style></head><body> <div class="pf">这里是系统标题栏,我们想要保持固定</div> <div> <table width="100%" border="1"> <script type="text/javascript" language="javascript"> for (i = 0; i < 50; i++) { document.write("<tr><td>系统集成考试必过!有没有信息,有" + (i + 1) + "</td></tr>"); } </script> </table> </div></body></html>
4、显示效果
继续下拉内容,发现内容如下:
===========================================================================
阅读全文
0 0
- jquery实现滚动下拉标题浮动固定显示
- asp.net开发中利用jquery来实现滚动下拉标题浮动固定显示
- jquery实现滚动条下拉DIV固定在头部不动
- jquery实现滚动条下拉DIV固定在头部不动
- jquery实现标题固定
- jQuery 顶部导航跟随滚动,固定浮动在顶部
- jquery+css实现滚动固定侧边栏
- jquery实现的固定位置下拉隐藏上拉显示悬浮导航菜单特效
- javascript 条形滚动显示公告标题实现
- Android ListView顶部固定浮动标题
- JQuery实现的页面滚动时浮动窗口控件
- jQuery实现页面滚动时层智能浮动定位
- jQuery实现浮动层跟随页面滚动效果
- js页面滚动浮动层智能定位(jQuery)实现
- jQuery实现页面滚动时层智能浮动定位
- 页面滚动时层智能浮动定位,jQuery/MooTools实现
- jQuery实现页面滚动时层智能浮动定位
- jQuery实现固定顶部 定位滚动导航效果代码
- RabbitMQ入门到高级
- 情感分析小试
- uvc摄像头代码解析4
- 属性解析(3)
- java虚拟机——运行时数据区概述
- jquery实现滚动下拉标题浮动固定显示
- Neo4j-3.0.3 (Debian 8)
- (五)redis常用数据类型 Set
- 环信SDK 头像、昵称、表情自定义和群聊设置的实现 一(附源码)
- ORCL存储过程跑到一半,如何停止下来,kill掉,kill掉
- uvc摄像头代码解析5
- tomcat tomee 配置 数据源 (含 XA 数据源)
- linux7下mariadb主从搭建
- uvc摄像头代码解析6