jQuery实现滑动页面固定顶部显示(可根据显示位置消失与替换)

 更新时间:2015年10月30日 13:43  点击:2516

本文实例讲述了jQuery实现滑动页面固定顶部显示(可根据显示位置消失与替换)。分享给大家供大家参考,具体如下:

这里介绍的jQuery拉动页面固定顶部显示,及自动消失效果,可能ie浏览器下有问题,不过火狐什么的都可以运行看效果,一个简单的网页特效,也是很常用的“回到顶部”效果,有兴趣的看一下。

运行效果截图如下:

在线演示地址如下:

http://demo.jb51.net/js/2015/jquery-fix-top-cha-show-codes/

具体代码如下:

<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>回到顶部:哭泣的小丑</title><script src="jquery-1.6.2.min.js"></script><!-- CSS模板清除 --><style>html, body, div, span, applet, object, iframe,h1, h2, h3, h4, h5, h6, p, blockquote, pre,a, abbr, acronym, address, big, cite, code,del, dfn, em, img, ins, kbd, q, s, samp,small, strike, strong, sub, sup, tt, var,b, u, i, center,dl, dt, dd, ol, ul, li,fieldset, form, label, legend, input,table, caption, tbody, tfoot, thead, tr, th, td,article, aside, canvas, details, embed,figure, figcaption, footer, header, hgroup,menu, nav, output, ruby, section, summary,time, mark, audio, video {margin: 0;padding: 0;border: 0;font-size: 100%;}article, aside, details, figcaption, figure,footer, header, hgroup, menu, nav, section {display: block;float:left;}select, input, button,button img, label {vertical-align: middle;}body {font:normal 12px/1.5 "Microsoft Yahei","微软雅黑",Tahoma,Arial,Helvetica,STHeiti; webkit-font-smoothing:antialiased;-moz-font-smoothing: subpixel-antialiased; color:#666;}ol, ul {list-style: none;}blockquote, q {quotes: none;}blockquote:before, blockquote:after,q:before, q:after {content: '';content: none;}table {border-collapse: collapse;border-spacing: 0;}em {font-style: normal}select, input, button, button img, label {vertical-align:middle;}input {font-family:"Microsoft Yahei","微软雅黑";webkit-font-smoothing:antialiased;-moz-font-smoothing: subpixel-antialiased}input, input:focus, button, button:focus, select,textarea, textarea:focus {outline:none; -moz-outline:none; -webkit-outline:none; }input:focus { outline:none; -moz-outline:none; -webkit-outline:none; }textarea {resize:none;}a {color:#666; text-decoration:none;} a:hover {text-decoration:underline;}a:focus {outline:none; -moz-outline:none;-webkit-outline:none;}body {min-width: 960px;}</style><!-- CSS模板清除 E--><!-- main CSS --><style>body{background:#e7e7e7;}.clearfix:before, .clearfix:after, .container_24:before, .container_24:after { content: '.'; display: block; overflow: hidden; visibility: hidden; font-size: 0; line-height: 0; width: 0; height: 0;}.clearfix:after, .container_24:after { clear: both; }.Xc_main{width:750px;margin:0 auto;position:relative;}.Xc_left{float:left;}.Xc_left h1{font-size:24px;padding-top:25px;}.Xc_right{float:right;width:600px;}.Xc_right .Xc_list{margin:10px 0 10px 0;}.Xc_list_top,.Xc_list_main{background:#fff;padding:10px;border:1px solid #ccc;}.Xc_list_top{margin-bottom:10px;}.Xc_gg{width:90px;height:90px;border:1px solid #ccc;background:#fff;text-align:center;}.Xc_bottom{height:650px;background:#fff;padding:10px;border:1px solid #ccc;position:relative;}</style><!-- main CSS E--></head><script>$(function () { $(".Xc_list_top").css("width",$(".Xc_list_main").width()); var resetRightPanelPostion = function () { var msie6 = $.browser.msie && $.browser.version == '6.0' && $.browser.version < 7; if ($.browser.safari) {  bodyelem = $("body"); } else {  bodyelem = $("html,body"); } var bodyTop = bodyelem.scrollTop(); var top = $(".Xc_left").offset().top; //var t = $("#public_footer").offset().top; var t = $("#footerDestinationBox").offset().top; //var bottom = $("#footerDestinationBox").offset().top;  for(var i = 0 ; i < $(".Xc_list .Xc_list_top").length ; i++){   if (bodyTop >= top && ((bodyTop + $(".Xc_left").outerHeight()) < t)) {    if (!msie6) {     if (bodyTop + $(".Xc_gg").outerHeight() >= t) {      $(".Xc_gg").removeClass('fixed').css({       "position": "absolute",       "top": t - $(".Xc_gg").outerHeight() + "px"      });     } else {      $(".Xc_gg").css({       "position": "fixed",       "top": 0      });     }    }   } else {    if (!msie6) {     $(".Xc_gg").css({      "position": "static"     });    }   }   if(bodyTop>$(".Xc_list").eq(i).offset().top){    $(".Xc_list_top").eq(i).css({position:"absolute",top:top-168});   }   if(bodyTop>$(".Xc_list").eq(i).offset().top){    $(".Xc_list_top").eq(i).css({position:"fixed",top:0});   }   if(bodyTop<=$(".Xc_list").eq(i).offset().top){    $(".Xc_list_top").eq(i).css({position:"static",top:0});   }  } }; window.onload = function () { if ($(".Xc_gg").length) {  resetRightPanelPostion();  $(window).scroll(function () {  resetRightPanelPostion();  }); } }})</script><body><div class="Xc_main clearfix"> <div class="clearfix" style="margin-top:90px;float:left;"> <div class="Xc_left">  <div class="Xc_gg">  <h1>小丑</h1>  <div style="margin-top:40px;">Q群:<em style="color:#0069D6;">150508281</em></div>  </div> </div> </div> <div class="Xc_right clearfix">  <div class="Xc_list">  <div class="Xc_list_top" id="Xc_list_top">top 1</div>  <div class="Xc_list_main" style="height:300px;background:#fff;">  </div> </div> <div class="Xc_list">  <div class="Xc_list_top">top 2</div>  <div class="Xc_list_main" style="height:300px;background:#fff;">  </div> </div> <div class="Xc_list">  <div class="Xc_list_top">top 3</div>  <div class="Xc_list_main" style="height:300px;background:#fff;">  </div> </div> <div class="Xc_list">  <div class="Xc_list_top">top 4</div>  <div class="Xc_list_main" style="height:300px;background:#fff;">  </div> </div> <div class="Xc_list">  <div class="Xc_list_top">top 5</div>  <div class="Xc_list_main" style="height:300px;background:#fff;">  </div> </div> <div class="Xc_list">  <div class="Xc_list_top">top 6</div>  <div class="Xc_list_main" style="height:300px;background:#fff;">  </div> </div> </div></div><div class="Xc_bottom clearfix" id="footerDestinationBox"> <div style="position:absolute;top:40px;right:50px;"> by 蓝色理想 @哭泣的小丑</div></div></body></html>

希望本文所述对大家jQuery程序设计有所帮助。

[!--infotagslink--]

相关文章

  • jquery实现加载更多"转圈圈"效果(示例代码)

    这篇文章主要介绍了jquery实现加载更多"转圈圈"效果,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-11-10
  • 自己动手写的jquery分页控件(非常简单实用)

    最近接了一个项目,其中有需求要用到jquery分页控件,上网也找到了需要分页控件,各种写法各种用法,都是很复杂,最终决定自己动手写一个jquery分页控件,全当是练练手了。写的不好,还请见谅,本分页控件在chrome测试过,其他的兼容性...2015-10-30
  • jQuery+jRange实现滑动选取数值范围特效

    有时我们在页面上需要选择数值范围,如购物时选取价格区间,购买主机时自主选取CPU,内存大小配置等,使用直观的滑块条直接选取想要的数值大小即可,无需手动输入数值,操作简单又方便。HTML首先载入jQuery库文件以及jRange相关...2015-03-15
  • iOS设置UIButton文字显示位置和字体大小、颜色的方法

    这篇文章给大家分享了iOS如何设置UIButton的文字显示位置和字体的大小、颜色,文中给出了示例代码,相信对大家的学习和理解很有帮助,有需要的朋友们下面来一起看看吧。...2020-06-30
  • jQuery实现非常实用漂亮的select下拉菜单选择效果

    本文实例讲述了jQuery实现非常实用漂亮的select下拉菜单选择效果。分享给大家供大家参考,具体如下:先来看如下运行效果截图:在线演示地址如下:http://demo.jb51.net/js/2015/js-select-chose-style-menu-codes/具体代码如...2015-11-08
  • jquery实现的伪分页效果代码

    本文实例讲述了jquery实现的伪分页效果代码。分享给大家供大家参考,具体如下:这里介绍的jquery伪分页效果,在火狐下表现完美,IE全系列下有些问题,引入了jQuery1.7.2插件,代码里有丰富的注释,相信对学习jQuery有不小的帮助,期...2015-10-30
  • Jquery Ajax Error 调试错误的技巧

    JQuery使我们在开发Ajax应用程序的时候提高了效率,减少了许多兼容性问题,我们在Ajax项目中,遇到ajax异步获取数据出错怎么办,我们可以通过捕捉error事件来获取出错的信息。在没给大家介绍正文之前先给分享Jquery中AJAX参...2015-11-24
  • jQuery 2.0.3 源码分析之core(一)整体架构

    拜读一个开源框架,最想学到的就是设计的思想和实现的技巧。废话不多说,jquery这么多年了分析都写烂了,老早以前就拜读过,不过这几年都是做移动端,一直御用zepto, 最近抽出点时间把jquery又给扫一遍我也不会照本宣科的翻译...2014-05-31
  • jQuery页面加载初始化常用的三种方法

    当页面打开时我们需要执行一些操作,这个时候如果我们选择使用jquery的话,需要重写他的3中方法,自我感觉没什么区 别,看个人喜好了,第二种感觉比较简单明了: 第一种: 复制代码 代码如下: <script type="text/javas...2014-06-07
  • php批量替换内容或指定目录下所有文件内容

    要替换字符串中的内容我们只要利用php相关函数,如strstr,str_replace,正则表达式了,那么我们要替换目录所有文件的内容就需要先遍历目录再打开文件再利用上面讲的函数替...2016-11-25
  • jquery中常用的SET和GET$(”#msg”).html循环介绍

    复制代码 代码如下: $(”#msg”).html(); //返回id为msg的元素节点的html内容。 $(”#msg”).html(”new content“); //将“new content” 作为html串写入id为msg的元素节点内容中,页面显示粗体的new content $(”...2013-10-13
  • jQuery Mobile开发中日期插件Mobiscroll使用说明

    这篇文章主要介绍了jQuery Mobile开发中日期插件Mobiscroll使用说明,需要的朋友可以参考下...2016-03-03
  • jQuery实现切换页面过渡动画效果

    直接为大家介绍制作过程,希望大家可以喜欢。HTML结构该页面切换特效的HTML结构使用一个<main>元素来作为页面的包裹元素,div.cd-cover-layer用于制作页面切换时的遮罩层,div.cd-loading-bar是进行ajax加载时的loading进...2015-10-30
  • jquery获取div距离窗口和父级dv的距离示例

    jquery中jquery.offset().top / left用于获取div距离窗口的距离,jquery.position().top / left 用于获取距离父级div的距离(必须是绝对定位的div)。 (1)先介绍jquery.offset().top / left css: 复制代码 代码如下: *{ mar...2013-10-13
  • jQuery实现鼠标滑过链接控制图片的滑动展开与隐藏效果

    本文实例讲述了jQuery实现鼠标滑过链接控制图片的滑动展开与隐藏效果。分享给大家供大家参考,具体如下:这里演示jQuery实现鼠标移动到链接上,滑动展开/隐藏图片效果,鼠标放在“上一页”“下一页”上,立即浮现出所对应的图...2015-10-30
  • jQuery+PHP发布的内容进行无刷新分页(Fckeditor)

    这篇文章将使用jQuery,并结合PHP,将Fckeditor发布的内容进行分页,并且实现无刷新切换页面。 本文假设你是WEB开发人员,掌握了jQuery和PHP相关知识,并且熟知Fckeditor的配置和使用。...2015-10-23
  • jQuery实现带玻璃流光质感的手风琴特效

    jQuery实现带玻璃流光质感的手风琴特效是一款基于jQuery+CSS3实现的带玻璃流光质感的手风琴特效,分享给大家,具体如下效果图:具体代码如下:html代码: <section class="strips"> <article class="strips__strip"> <di...2015-11-24
  • jQuery 1.9使用$.support替代$.browser的使用方法

    jQuery 从 1.9 版开始,移除了 $.browser 和 $.browser.version , 取而代之的是 $.support 。 在更新的 2.0 版本中,将不再支持 IE 6/7/8。 以后,如果用户需要支持 IE 6/7/8,只能使用 jQuery 1.9。 如果要全面支持 IE,并混合...2014-05-31
  • jQuery+slidereveal实现的面板滑动侧边展出效果

    我们借助一款jQuery插件:slidereveal.js,可以使用它控制面板左右侧滑出与隐藏等效果,项目地址:https://github.com/nnattawat/slideReveal。如何使用首先在页面中加载jquery库文件和slidereveal.js插件。复制代码 代码如...2015-03-15
  • jquery validate demo 基础

    jQuery Validate 插件为表单提供了强大的验证功能,让客户端表单验证变得更简单,同时提供了大量的定制选项,满足应用程序各种需求。该插件捆绑了一套有用的验证方法,包括 URL 和电子邮件验证,同时提供了一个用来编写用户自...2015-10-30