记录生活 学习SEO优化 | 他日若遂凌云志 敢笑黄巢不丈夫
>>Home > 学习笔记 > jQuery特效 > 滑动侧边导航栏jQuery来实现

滑动侧边导航栏jQuery来实现

Tags: | | 作者:海天无影

今天是周末,所以昨天夜里海天很正常的玩到很晚,今天也很正常的很晚的才起来。不过现在好多了,海天现在星期天睡到2点左右就自己醒了,要是原来尽饱睡睡到个四五点钟。起来以后收拾下就去参加朋友的婚礼,婚礼嘛,就那样,没什么好介绍的,呵呵。

参加完婚礼回来是比较晚了,不过闲着也是无事,海天不能断更哈,就翻了下博客,看看有什么好的东西拿出来分享。于是就有了这篇的文章《滑动侧边导航栏jQuery来实现》

侧边滑动导航栏

侧边滑动导航栏

滑动侧边导航栏的效果,大家刻意看海天的博客文章页的左侧,那个会随着页面滚动而滑动的导航栏,点击按钮后可以返回顶部、到达底部或评论的功能,见右图:

功能是在木木同学那儿看到的,此方法差不多能够通用在各个浏览器下,而且滑动效果也还是很不错的。加上滑动侧边导航栏,碰到很长的页面不再需要一点点的向下挪动,而且可以直接点击到达评论区,相当的提高用户体验。当然你还可以加上其他自己想要的功能,比如订阅RSS等功能,都是可以实现的。方法如下:

1、将图片文件上传至主题中images文件夹中。 download-下载,侧边滑动导航栏文件

2、将以下代码加入到主题中的footer.php文件末位的</body>之前:

<div id="shangxia" style="top: 300px;"><div id="shang"></div><div id="comt"></div><div id="xia"></div></div>

3、将以下CSS样式代码加到主题的Style.css末尾:

#shangxia{position:absolute;top:40%;left:50%;margin-left:-520px;display:block;z-index:2;}
#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;}

4、在主题的head.php文件中的 JS代码部分 添加下面代码:

<script type="text/javascript">
jQuery(document).ready(function($){
var s= $('#shangxia').offset().top; //取得id="shangxia"元素相对当前窗口的高度,并赋值给 s
$(window).scroll(function (){ //浏览器滚动条触发事件
$("#shangxia").animate({top : $(window).scrollTop() + s + "px" },{queue:false,duration:500});
//添加id="shangxia"元素自定义动画,使其滑动"滚动条距顶部高度+ s "距离,动画过程为500毫秒;
});
$('#shang').click(function(){$('html,body').animate({scrollTop: '0px'}, 800);});
//点击id="shang"对象时,滑动至相对浏览器滚动条为0px(即顶部),时间为800毫秒
$('#comt').click(function(){$('html,body').animate({scrollTop:$('.commentlist').offset().top}, 800);});
//点击id="comt"对象时,滑动至id="comment"相对浏览器滚动条的距离,时间为800毫秒
$('#xia').click(function(){$('html,body').animate({scrollTop:$('#footer').offset().top}, 800);});
</script>

最后,还需要调用jQuery库,但需要注意的是,这里不能用GOOGLE的mini 1.3.2版的jQ库,正如海天上次一篇文章《图片适当载入渐显特效,基于jQuery.Lazyload》中所说,GOOGLE的mini 1.3.2版的jQ库没有这两篇文章所需的jQ程序。所以大家还是一样使用Wordpress自带的jQ库吧。
文件位于:/wp-includes/js/jquery/jquery.js。
调用方法:
<script type='text/javascript' src='/wp-includes/js/jquery/jquery.js?ver=1.3.2'></script>

日志信息 »

该日志于2010-05-16 22:08由 海天无影 发表在jQuery特效分类下, 你可以发表评论。除了可以将这个日志以保留源地址及作者的情况下转载到你的网站或博客,还可以通过RSS 2.0订阅这个日志的所有评论。

32条评论▼点击进行评论


  1. Warning: copy(/home/wwwroot/haitian/blog/avatar/ae1d9cb02574d579039efc62a447f2f3.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    在很多地方都看到这个按钮组了


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 是啊
      滑动效果不错,而且你也可以添加自己想要的功能~


  2. Warning: copy(/home/wwwroot/haitian/blog/avatar/e657612476777faf50d5f28627975291.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    这段js代码貌似只能在php中用。 :|


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 是 吗?
      这个不是JS吗?JS 不是通用的吗?


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/0add08e212ec07498618635abac4850f.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      ……JQ..ASP,HTML下也可以用的,跟php没什么关系


      • Warning: copy(/home/wwwroot/haitian/blog/avatar/e657612476777faf50d5f28627975291.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
        回复

        因为这段js里面传递了php变量,所以要换在其它的语言中应用,还得稍微改一下.


        • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
          回复

          $是php中的定义?还是?
          额~


  3. Warning: copy(/home/wwwroot/haitian/blog/avatar/0dcedda7123567217b5ce259e203a209.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    不错,可以一试


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      嗯 加上去蛮好玩的 呵呵~


  4. Warning: copy(/home/wwwroot/haitian/blog/avatar/c97d5ed7936e8a93bf668d771bc0eb00.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    原来海天侧边栏上的flash是时钟啊 今天突然发现


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 时钟是右侧边
      那你原来以为是什么啊 呵呵~


      • Warning: copy(/home/wwwroot/haitian/blog/avatar/c97d5ed7936e8a93bf668d771bc0eb00.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
        回复

        我原以为是什么小游戏呢 :mrgreen:


  5. Warning: copy(/home/wwwroot/haitian/blog/avatar/8a696fb2b60f79867e39e7803303fc7a.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    这玩意跟个小尾巴似的,怎么也甩不掉。


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      哈哈 就是要你甩不掉
      让你随用随到


  6. Warning: copy(/home/wwwroot/haitian/blog/avatar/0f6840987df0326df65aaa142fd9245b.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    昨晚出去k歌了~
    今天把回访都补上~


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 K歌啊 看来玩的很开心的啊~ :lol:


  7. Warning: copy(/home/wwwroot/haitian/blog/avatar/c4668a51a1479f6c344c7b79636c2236.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    这个小东西很好


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      恩 比较方便的说 呵呵~


  8. Warning: copy(/home/wwwroot/haitian/blog/avatar/152f90fdd68816e41c53dab837931b2a.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    好长时间没来看海天了,今天特意来光临。


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 欢迎光临啊~


  9. Warning: copy(/home/wwwroot/haitian/blog/avatar/d94967b298c3fcfed3f8e5a6c5181f42.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    最好让它固定,滑动有点头晕 :mrgreen:


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 可能是在评论区那一块 图片要加载 会卡一点 出现的问题吧
      我来先把评论头像图片 直接加载吧
      很多人反应会卡~
      你再帮忙看看滑动是不是会流畅很多~


  10. Warning: copy(/home/wwwroot/haitian/blog/avatar/3b459060bcea2c93f951b85abc9904b4.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    很好很强大,我喜欢,回头搞个去


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      呵呵 加一个 比较方便用户的


  11. Warning: copy(/home/wwwroot/haitian/blog/avatar/d94967b298c3fcfed3f8e5a6c5181f42.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    固定在中间不是很好吗?


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 比较新奇好玩啊
      话说可能能增加点UEO吧~


  12. Warning: copy(/home/wwwroot/haitian/blog/avatar/870740f1294e031dfe7ef1cbb020cff2.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    那个最后一行代码,也就是jQuery库,应该放在哪里呀?


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      最后一个调用jQ库的要放在页面的前面
      一般放在前面 调用js代码之前


      • Warning: copy(/home/wwwroot/haitian/blog/avatar/870740f1294e031dfe7ef1cbb020cff2.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
        回复

        呵呵,一般都是放在header.php的哈。我用的是WP


  13. Warning: copy(/home/wwwroot/haitian/blog/avatar/d8973823d10141e42239fc8233508f65.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    菜鸟来请教一下。1.header.php里的js部分在哪里,怎么没有见到啊
    2.调用js,具体怎么调用,还望耐心解答一下。
    ishoage@gmail.com


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      看了你的博客 你的博客本身没有调用过js
      那你就放在css下面
      调用方法 我文章最后一句就是调用方法啊


  14. Warning: copy(/home/wwwroot/haitian/blog/avatar/2dec826afef16639d2f3dfe31d8ef4f9.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    :cry: 我的博客貌似实现不了,如果博主有空帮我看一下,耐心等待…Thx!


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      因为我不好修改 帮你猜测几个吧
      一、感觉js没有调用上
      1、看看代码中有没错误,会不会有标点的半角全角问题
      2、将代码加入到你主题的js文件调用中
      3、换个jQ库,我看你那个虽然是1.3.2但里面貌似是1.4.2
      二、将div层放到hearder.php文件试试


      • Warning: copy(/home/wwwroot/haitian/blog/avatar/2dec826afef16639d2f3dfe31d8ef4f9.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
        回复

        貌似这个主题没有调用js,所以可以把js代码和调用jq库的代码放到header.php中的head里么?


        • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
          回复

          恩 可以的
          调用js和jQ 也可以放在footr.php中


  15. Warning: copy(/home/wwwroot/haitian/blog/avatar/32771531dda6fb833937f8a89d24553e.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    我正的不会滑动。不知道哪里出问题了。


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 不是可以了吗?


  16. Warning: copy(/home/wwwroot/haitian/blog/avatar/f9bf585deaa433a947c28e815077e668.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    :cry: 倒霉我在本地测试了,图片挂在哪里居然不动声色。看了看代码毛错

    可以的话麻烦到我blog叫下我···试了都不行


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 才看到
      但貌似没有了


      • Warning: copy(/home/wwwroot/haitian/blog/avatar/f9bf585deaa433a947c28e815077e668.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
        回复

        不会动好给我删了···一般是那没设置好


  17. Warning: copy(/home/wwwroot/haitian/blog/avatar/808a906efac39977eb959884bd0d5d1a.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    我的也是啊,有样子没效果。图片挂在那里不动,是什么问题呢?


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 不好意思啊 才看到
      你是 不是js没加载呢?


  18. Warning: copy(/home/wwwroot/haitian/blog/avatar/244714b7504e1a40f3d2c71ffb4c8877.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    SOS 为什么我的不能动~~~


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 不好意思啊 才看到
      看来你已经解决了啊


  19. Warning: copy(/home/wwwroot/haitian/blog/avatar/8e0c811450c33a147ca322b3e29a9413.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    我的点向下的也是向上
    点评论也没反应


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 不好意思啊 才看到
      你是 不是js没加载呢?
      你的网站打不开了


  20. Warning: copy(/home/wwwroot/haitian/blog/avatar/56db66f39c31e875d30d77f2441eaba0.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    能帮忙看看啥问题不?没反应啊


  21. Warning: copy(/home/wwwroot/haitian/blog/avatar/dc3ab43ebccf44f3a98e3a1b76d82768.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    呵呵 我都按这做了乍没反应呢?


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/3d58c5baea42043cdd0f012c22cfd774.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      额 没看到 什么情况哎


  22. Warning: copy(/home/wwwroot/haitian/blog/avatar/95fd33cf9666d6d900fd6fd93997c1fb.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    请问怎么固定在侧栏


    • Warning: copy(/home/wwwroot/haitian/blog/avatar/ad2af2fc136a37514b274fb64400dbe8.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
      回复

      竟然发现乃了。。。


      • Warning: copy(/home/wwwroot/haitian/blog/avatar/95fd33cf9666d6d900fd6fd93997c1fb.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
        回复

        囧。。。我已经成功了。。


  23. Warning: copy(/home/wwwroot/haitian/blog/avatar/ad2af2fc136a37514b274fb64400dbe8.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    不会浮动也不能按。。
    估计我有什么放错位置了。。
    第4步的代码和调用放哪里?


  24. Warning: copy(/home/wwwroot/haitian/blog/avatar/698a1f942f143127cfd136f588634f58.jpg): failed to open stream: Permission denied in /home/wwwroot/haitian/blog/wp-content/themes/prowerV3.1/functions.php on line 169
    回复

    请问调用js那段代码应该放在哪儿啊 我是新手 不懂诶

icon_wink.gif icon_neutral.gif icon_mad.gif icon_twisted.gif icon_smile.gif icon_eek.gif icon_sad.gif icon_rolleyes.gif icon_razz.gif icon_redface.gif icon_surprised.gif icon_mrgreen.gif icon_lol.gif icon_idea.gif icon_biggrin.gif icon_evil.gif icon_cry.gif icon_cool.gif icon_arrow.gif icon_confused.gif icon_question.gif icon_exclaim.gif 

« 周杰伦2010年最新专辑《跨时代》试听下载 Dropbox不能用了,看看金山快盘怎么样 »