“返回顶部”所要的实现的功能是
我的博客左侧的那个返回顶部,移动到最下,以及到达评论区的功能
效果图
首先加载jquery(如果你的博客已经加载了,就不要重复加载jquery了)
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
然后新建一个huadong.js
里面写入如下内容:
- jQuery(document).ready(function($) {
- var s = $('#shangxia').offset().top;
- $(window).scroll(function() {
- $("#shangxia").animate({
- top: $(window).scrollTop() + s + "px"
- },
- {
- queue: false,
- duration: 500
- })
- });
- $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
- $('#shang').click(function() {
- $body.animate({
- scrollTop: '0px'
- },
- 400)
- });
- $('#xia').click(function() {
- $body.animate({
- scrollTop: $('#footer').offset().top
- },
- 400)
- });
- $('#comt').click(function() {
- $body.animate({
- scrollTop: $('#comments').offset().top
- },
- 400)
- });
- });
然后加载huadong.js:
- <script type="text/javascript" src="http://blueandhack.com/wp-content/themes/white-love/js/huadong.js"></script>
在文章头部写入如下代码:
- <?php if (is_home()) { ?>
- <div id="shangxia"><div id="shang"></div><div id="xia"></div></div>
- <?php } else { ?>
- <div id="shangxia"><div id="shang"></div><div id="comt"></div><div id="xia"></div></div>
- <?php } ?>
CSS代码如下:
- #shangxia{position:absolute;top:40%;left:50%;margin-left:-520px;display:block;}
- #shang{background:url(images/huadong.gif) no-repeat;position:relative;cursor:pointer;height:42px;width:32px;margin:10px 0;}
- #comt{background:url(images/huadong.gif) no-repeat center -45px;position:relative;cursor:pointer;height:32px;width:32px;margin:10px 0;}
- #xia{background:url(images/huadong.gif) no-repeat center -78px;position:relative;cursor:pointer;height:42px;width:32px;margin:10px 0;}
索要用到的素材(记得传到主题文件夹的images文件夹里)
此教程整理来自
木木博客今后我会多多给大家整理教程,给大家共享的
都是有关WORDPRESS主题美化&增强的
[ 此帖被blueandhack在2010-10-03 02:06重新编辑 ]