博客园边栏滚动隐藏代码

 1 $(document).ready(function(){
 2 
 3 $(".cnblogs_code pre").addClass("prettyprint"); 
 4 $(".code").toggleClass("prettyprint"); 
 5 
 6 window.setTimeout(prettyPrint, 1000);
 7 var str = "<li><div id='closeside'><a class='close-sidebar' style='cursor:pointer;'>关闭侧边栏</a><a class='show-sidebar' style='display:none;cursor:pointer'>显示侧边栏</a></div></li>";
 8 $('#navList').html($('#navList').html()+str);
 9 
10     var $sidebar   = $("#sideBar"),   
11         $window    = $(window),   
12         offset     = $sidebar.offset(),   
13         topPadding = 15;   
14   
15     $window.scroll(function() {   
16         if ($window.scrollTop() > offset.top) {   
17             $sidebar.stop().animate({   
18                 marginTop: $window.scrollTop() - offset.top + topPadding   
19             });   
20         } else {   
21             $sidebar.stop().animate({   
22                 marginTop: 0   
23             });   
24         }   
25     });   
26   
27   
28     $('.close-sidebar').click(function() {
29         $("#content").css('background','none');
30         $('.close-sidebar').hide();
31         $('.close-sidebar,#sideBar').fadeOut(500);
32         $('.show-sidebar').show();
33         window.setTimeout(function(){
34             $(".forFlow").css('margin','-18px 0 0 2px'); 
35             $("#mainContent").css('background','url("http://pic002.cnblogs.com/images/2012/25317/2012072712554778.gif") no-repeat 2px 0px'); 
36         },1000);
37     });
38 
39     $('.show-sidebar').click(function() {
40         $('.show-sidebar').hide();
41         $('.close-sidebar').show();
42         $(".forFlow").css('margin','-18px 0 0 235px'); 
43         $("#mainContent").css('background','url("http://pic002.cnblogs.com/images/2012/25317/2012072712554778.gif") no-repeat 235px 0px'); 
44         window.setTimeout(function(){
45             $('#sideBar').fadeIn(500);
46         },1000);
47     });
48 
49 });   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值