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 });
转载于:https://www.cnblogs.com/meetrice/archive/2012/07/27/2611749.html