You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
1.6 KiB
1 line
1.6 KiB
5 years ago
|
!function(n,t,h){if(void 0===n.csdn&&(n.csdn={}),!jQuery)return;n.csdn.fixedSidebar=function(t){var i={targetBox:h(".persion_article"),mainBox:h("main"),sidebar:h("aside"),direction:"right",position:"fixed",top:0,bottom:0,zIndex:99,sidebarRightMargin:8,sidebarLeftMargin:15};t&&h.extend(i,t);var o=i.sidebar.width(),r=i.targetBox.offset().top,s=!0,a=i.sidebar.height();function e(){if("right"===i.direction)var t=i.mainBox.offset().left+i.mainBox.width()-h(n).scrollLeft()+parseInt(i.sidebarLeftMargin);else t=i.mainBox.offset().left-i.sidebar.width()-h(n).scrollLeft()-parseInt(i.sidebarRightMargin);var e;e=h(n).scrollTop(),i.targetBox.height()<h(n).height()&&(i.sidebar.height()>a?r=i.sidebar.height()-a+r:r-=a-i.sidebar.height(),a=i.sidebar.height()),r+i.sidebar.height()<=h(n).height()?r<e?i.sidebar.css({position:i.position,top:parseInt(i.top)+"px","z-index":parseInt(i.zIndex),left:t,width:o,bottom:"auto"}):i.sidebar.removeAttr("style"):i.mainBox.height()>i.sidebar.height()?i.targetBox.height()<=h(n).height()&&i.targetBox.height()+r-e<=h(n).height()?i.sidebar.css({position:i.position,bottom:parseInt(i.bottom)+"px","z-index":parseInt(i.zIndex),left:t,width:o,top:"auto"}):i.targetBox.height()>h(n).height()&&i.targetBox.height()-e+i.mainBox.offset().top<=h(n).height()?i.sidebar.css({position:i.position,bottom:parseInt(i.bottom)+"px","z-index":parseInt(i.zIndex),left:t,width:o,top:"auto"}):i.sidebar.removeAttr("style"):i.sidebar.removeAttr("style"),s=!0}e(),h(n).on("scroll",function(){s&&(setTimeout(e,200),s=!1)}),h(n).on("resize",function(){e()})}}(window,document,jQuery);
|