saved_resource(2) 1.5 KB

1
  1. !function(t,e,i){if(void 0===t.csdn&&(t.csdn={}),!jQuery)return!1;t.csdn.fixedSidebar=function(e){function o(){if("right"===r.direction)var e=r.mainBox.offset().left+r.mainBox.width()-i(t).scrollLeft()+parseInt(r.sidebarLeftMargin);else var e=r.mainBox.offset().left-r.sidebar.width()-i(t).scrollLeft()-parseInt(r.sidebarRightMargin);!function(){var o=i(t).scrollTop();s+r.sidebar.height()<=i(t).height()?o>s?r.sidebar.css({position:r.position,top:parseInt(r.top)+"px","z-index":parseInt(r.zIndex),left:e,width:n,bottom:"auto"}):r.sidebar.removeAttr("style"):r.mainBox.height()>r.sidebar.height()?r.targetBox.height()<=i(t).height()&&r.targetBox.height()+s-o<=i(t).height()?o>s?r.sidebar.css({position:r.position,top:parseInt(r.top)+"px","z-index":parseInt(r.zIndex),left:e,width:n,bottom:"auto"}):r.sidebar.removeAttr("style"):r.targetBox.height()>i(t).height()&&r.targetBox.height()-o+r.mainBox.offset().top<=i(t).height()?r.sidebar.css({position:r.position,bottom:parseInt(r.bottom)+"px","z-index":parseInt(r.zIndex),left:e,width:n,top:"auto"}):r.sidebar.removeAttr("style"):r.sidebar.removeAttr("style"),a=!0}()}var r={targetBox:i(".persion_article"),mainBox:i("main"),sidebar:i("aside"),direction:"right",position:"fixed",top:0,bottom:0,zIndex:99,sidebarRightMargin:8,sidebarLeftMargin:15};e&&i.extend(r,e);var n=r.sidebar.width(),s=r.targetBox.offset().top,a=!0;o(),i(t).on("scroll",function(){a&&(setTimeout(o,100),a=!1)}),i(t).on("resize",function(){o()})}}(window,document,jQuery);