JAVASCRIPT   28
fixedSidebar
Guest on 2nd February 2023 02:14:19 PM


  1. ! function(t, e, i) {
  2.     if (void 0 === t.csdn && (t.csdn = {}, t.csdn.fixedSidebar = {}), !jQuery) return !1;
  3.     t.csdn.fixedSidebar = function(e) {
  4.         function o() {
  5.             if ("right" === r.direction) var e = r.mainBox.offset().left + r.mainBox.width() - i(t).scrollLeft() + parseInt(r.sidebarLeftMargin);
  6.             else var e = r.mainBox.offset().left - r.sidebar.width() - i(t).scrollLeft() - parseInt(r.sidebarRightMargin);
  7.             ! function() {
  8.                 var o = i(t).scrollTop();
  9.                 n + r.sidebar.height() <= i(t).height() ? o > n ? r.sidebar.css({
  10.                     position: r.position,
  11.                     top: parseInt(r.top) + "px",
  12.                     "z-index": parseInt(r.zIndex),
  13.                     left: e,
  14.                     width: s,
  15.                     bottom: "auto"
  16.                 }) : r.sidebar.removeAttr("style") : r.mainBox.height() > r.sidebar.height() ? r.targetBox.height() <= i(t).height() && r.targetBox.height() + n - o <= i(t).height() ? o > n ? r.sidebar.css({
  17.                     position: r.position,
  18.                     top: parseInt(r.top) + "px",
  19.                     "z-index": parseInt(r.zIndex),
  20.                     left: e,
  21.                     width: s,
  22.                     bottom: "auto"
  23.                 }) : r.sidebar.removeAttr("style") : r.targetBox.height() > i(t).height() && r.targetBox.height() - o + r.mainBox.offset().top <= i(t).height() ? r.sidebar.css({
  24.                     position: r.position,
  25.                     bottom: parseInt(r.bottom) + "px",
  26.                     "z-index": parseInt(r.zIndex),
  27.                     left: e,
  28.                     width: s,
  29.                     top: "auto"
  30.                 }) : r.sidebar.removeAttr("style") : r.sidebar.removeAttr("style"), a = !0
  31.             }()
  32.         }
  33.         var r = {
  34.             targetBox: i(".persion_article"),
  35.             mainBox: i("main"),
  36.             sidebar: i("aside"),
  37.             direction: "right",
  38.             position: "fixed",
  39.             top: 0,
  40.             bottom: 0,
  41.             zIndex: 99,
  42.             sidebarRightMargin: 8,
  43.             sidebarLeftMargin: 15
  44.         };
  45.         e && i.extend(r, e);
  46.         var s = r.sidebar.width(),
  47.             n = r.targetBox.offset().top,
  48.             a = !0;
  49.         o(), i(t).on("scroll", function() {
  50.             a && t.csdn.fixedSidebar.stopListener && (setTimeout(o, 100), a = !1)
  51.         }), i(t).on("resize", function() {
  52.             o()
  53.         })
  54.     }, t.csdn.fixedSidebar.version = "1.1.7", t.csdn.fixedSidebar.stopListener = !0
  55. }(window, document, jQuery);

Raw Paste

Login or Register to edit or fork this paste. It's free.