jQuery实现滑动导航效果

这周,本博修改了很多地方,比如 评论框的CSS about页面 上下导航滑动效果,反响很好, 回到顶部
     至于好到什么程度了?特别是 滑动导航效果,有人Q我,有人mail我,还有人Fo我,
问我怎么实现的。囧,我总不能一人解释一次,发一次链接。
于是有了本文,希望大家也能做出自己喜欢的效果;本站效果见右图————–>>

补充一下:这个效果可以做成别的用处,比如在首页浮动显示你的 Twi-t-ter地址,
   订阅地址,照片。。。等等

这个效果是 我的博友 林木木 同学在 滑动导航栏也来滑动 一文中折腾的,具体实践如下:

 

////////////////第1步////////////////////
//1.将下面代码添加到主题  footer.php  末尾的 </b ody> 标签前面;
<div id="shangxia" style="top: 300px;"><div id="shang"></div><div id="comt"></div><div id="xia"></div></div>
////////////////第2步////////////////////
//2.将以下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;}
////////////////第3步////////////////////
//3.同样在主题的 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> 
////////////////第4步////////////////////
//4.以上功能必须要调用jQuery库,比如在 head 中调用下面的代码:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>

还有问题或不能实现的,可以跟帖联系。

版权所有© HzlzH | 本文采用 BY-NC-SA 进行授权
转载需注明 转自: 《jQuery实现滑动导航效果

相关文章

{ Leave a Reply ? }

  1. 万戈 China Mozilla Firefox Windows

    效果不错,挺好玩的

  2. 一米 China Google Chrome Windows

    这个东西很早就喜欢了,不过最近弄论文呢,没时间啊。

  3. 阳光宅男 China Google Chrome Windows

    這個不錯,wange那也有了,我記得

  4. diyidu China Internet Explorer Windows

    一直在找这个呢,谢谢分享.

  5. 扯远了 China Google Chrome Windows

    技术贴,收藏先。能用上的时候就不至于手忙脚乱的找了

  6. zwwooooo China Mozilla Firefox Windows

    木木的这个折腾还是挺多人喜欢的,包括左边的“返回顶部”滚动效果

  7. 卢松松 China Mozilla Firefox Windows

    如果有预览效果会好点

  8. 小辉网 China Internet Explorer Windows

    这个很先进! :-D

  9. 第一页 China Mozilla Firefox Windows

    这个东西很不错
    我喜欢! :roll:

  10. 二维码 China Internet Explorer Unknow Os

    博客不错,我的博客是百度博客,呵呵有空多交流。

  11. Ray Chow China Google Chrome Windows

    好好玩,收藏了

  12. andy China SouGou Browser Windows

    :roll: 我怎么看不到效果。。。而且我也在博客上用了,没反应啊。。怎么回事????

  13. 皓辰 China 360 Browser Windows

    木木童鞋的吧,用处不大,可能会把网页整卡……

  14. 陆少博 China 360 Browser Windows

    效果挺好的。学习了。不错。

  15. Anonymous China Internet Explorer Windows

    搞jquery的这么多了啊!!
    或者说是个人都懂点网页开发了?

  16. 蓝梦星缘 China Internet Explorer Windows

    请问huadong.gif要放在哪里?

  17. Anonymous China Internet Explorer Windows

    :lol: :twisted:

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

:wink: :twisted: :roll: :oops: :mrgreen: :lol: :idea: :evil: :cry: :arrow: :?: :-| :-x :-o :-P :-D :-? :) :( :!: 8-O 8)