jQuery实现带有动画效果的回到顶部和底部代码

2019-12-17,,,,,

本文实例讲述了jQuery实现带有动画效果回到顶部底部代码。分享给大家供大家参考,具体如下:

这款动画版的回到顶部和底部效果代码,也算是比较常见的一款网页特效了,像淘宝网就有这种效果,使用了jQuery插件,加入了动画效果。

运行效果截图如下:

在线演示地址如下:

http://demo.jb51.net/js/2015/jquery-animate-style-scroll-top-buttom-codes/

具体代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>动画版的回到顶部和底部效果代码</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<style type="text/css">
body{padding:0px;margin:0px;}
#roll_top,#fall,#ct{position:relative;cursor:pointer;height:40px;width:15px;}
#roll_top{background:url(images/roll.png) no-repeat;}
#fall{background:url(images/roll.png) no-repeat 0 -80px;}
#ct{background:url(images/roll.png) no-repeat 0 -40px;}
#roll{display:block;width:15px;margin-right:-508px;position:fixed;right:50%;top:50%;_margin-right:-507px;_position:absolute;_margin-top:300px;_top:expression(eval(document.documentElement.scrollTop));}
</style>
<!--[if IE]>
<style type="text/css">
/* 修正IE6振动bug */
html,body{background-image:url(about:blank);background-attachment:fixed;}
</style>
<![endif]-->
<script type="text/javascript" src="jquery1.3.2.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
  $('#roll_top').click(function(){$('html,body').animate({scrollTop: '0px'}, 800);}); 
  $('#ct').click(function(){$('html,body').animate({scrollTop:$('.ct').offset().top}, 800);});
  $('#fall').click(function(){$('html,body').animate({scrollTop:$('.footer,.footer_a').offset().top}, 800);});
});
</script>
</head>
<body>
预览效果时左下角会提示错误,而且看不到效果,刷新一下就可以看到效果了<br>
<div class="head">这里是页面顶部</div>
<div id="roll">
  <div title="回到顶部" id="roll_top"></div>
  <div title="转到底部" id="fall"></div>
</div>
<div id="content" style="height:2000px;"></div>
<div class="footer">这里是页面底部</div>
</body>
</html>

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

您可能感兴趣的文章:

  • jquery实现的动态回到顶部特效代码
  • jQuery回到顶部的代码
  • jquery实现点击页面回到顶部
  • jquery网页回到顶部效果(图标渐隐,自写)
  • jQuery实现分章节锚点“回到顶部”动画特效代码
  • jquery实现跳到底部,回到顶部效果的简单实例(类似锚)
  • 如何利用JQuery实现从底部回到顶部的功能
  • js+JQuery返回顶部功能如何实现
  • jQuery 顶部导航跟随滚动条滚动固定浮动在顶部
  • jquery实现固定顶部导航效果(仿蘑菇街)
  • jQuery实现简单的回到顶部totop功能示例

《jQuery实现带有动画效果的回到顶部和底部代码.doc》

下载本文的Word格式文档,以方便收藏与打印。