jQuery带微博按钮返回顶部

好吧,写这篇文章主要是为了刷一下存在感的,有是小半月没更新了,发生了很多事,让人无力吐槽;俗话说,好像不是俗话,人艰不拆......
为博客添加带微博按钮返回顶部效果,具体效果如下
gotop
html代码部分

<div id="share">
<a id="totop" title="">返回顶部</a>
<a href="http://weibo.com/shenghao2011" target="_blank" class="sina">新浪微博</a>
<a href="http://t.qq.com/shenghao_liu"  target="_blank" class="tencent">腾讯微博</a>
</div>

Js代码部分

//scrolltotop
$(function(){
        //首先将#back-to-top隐藏
        $("#totop").hide();
        //当滚动条的位置处于距顶部100像素以下时,跳转链接出现,否则消失
        $(function () {
            $(window).scroll(function(){
                if ($(window).scrollTop()>100){
                    $("#totop").fadeIn();
                }
                else
                {
                    $("#totop").fadeOut();
                }
            });
            //当点击跳转链接后,回到页面顶部位置
            $("#totop").click(function(){
                $('body,html').animate({scrollTop:0},500);
                return false;
            });
        });
    }); 

css代码部分

/*share_start*/
#share {position:fixed;_position:absolute;_top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight)-34+"px");bottom:34px;left:95%;width:30px;zoom:1;}
#share a{background-image:url(images/share.png); background-repeat:no-repeat; display:block; width:30px; height:30px; margin-bottom:2px; overflow:hidden; text-indent:-999px;-webkit-transition: all 0.2s ease-in-out;-moz-transition: all 0.2s ease-in-out;-o-transition: all 0.2s ease-in-out;-ms-transition: all 0.2s ease-in-out;transition: all 0.2s ease-in-out;}
#share a{}
#share .sina {background-position:0 0; position:absolute; bottom:32px;}
#share a.sina:hover { background-position:-30px 0;}
#share .tencent { background-position:0 -30px; position:absolute; bottom:0;}
#share a.tencent:hover { background-position:-30px -30px;}
#share a#totop{background-position:0 -120px;position:absolute;bottom:64px;cursor:pointer;}
#share a#totop:hover {background-position:-30px -120px;}
/*share_end*/

其他具体CSS细节请自行调节,当然页面引入jquery.js时必须的,搞定收工。
最后放一个演示地址:Demo

评论 ( 20)
  1. 沙发
    馒头饭MADfan 2013-12-11 03:31

    慢慢上升,效果不错~

  2. 板凳
    空空裤兜 2013-11-30 13:17

    微博是无孔不入啊,我还没养成刷微博的习惯,怎么破

  3. 地板
    不给力的面条 2013-11-08 14:30

    我有小火箭

  4. 4 楼
    记忆碎片 2013-11-07 05:09

    这个挺好的

  5. 5 楼
    从良未遂 2013-11-05 03:46

    纯支持了,有没有那种到底部,到评论的那种?

    • 回复
      andy 2013-11-05 07:29
      @从良未遂 其实是有的, a id="pinglun" href="#respond"看下你评论框那里id是什么;到底部的话就是href="#footer"
  6. 6 楼
    有点蓝 2013-11-01 23:07

    一个效果带来无限可能

  7. 7 楼
    海涛 2013-11-01 09:32

    哇咔咔,现在图标都win8风格了,还是可以。不错,期待更多好的分享。。。

  8. 8 楼
    Louis Han 2013-10-31 23:06

    带微博按钮 又更近一步了

  9. 9 楼
    海棠秋客 2013-10-31 06:18

    学到,期待博主更多分享,持续关注

  10. 10 楼
    小蜜蜂 2013-10-31 04:38

    没看出来什么效果呀