mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-27 01:33:04 +00:00
feat: sticky top bar
This commit is contained in:
parent
4683d790f6
commit
40bdb505df
4 changed files with 21 additions and 18 deletions
|
@ -1,6 +1,7 @@
|
||||||
<script src="/js/jquery-2.x.min.js"></script>
|
<script src="/js/jquery-2.x.min.js"></script>
|
||||||
<script src="/js/clipboard.min.js"></script>
|
<script src="/js/clipboard.min.js"></script>
|
||||||
<script src="/js/jquery.scrollbar.min.js"></script>
|
<script src="/js/jquery.scrollbar.min.js"></script>
|
||||||
|
<script src="/js/jquery.sticky-kit.min.js"></script>
|
||||||
<script src="/js/featherlight.min.js"></script>
|
<script src="/js/featherlight.min.js"></script>
|
||||||
<script src="/js/html5shiv-printshiv.min.js"></script>
|
<script src="/js/html5shiv-printshiv.min.js"></script>
|
||||||
<script src="/js/highlight.pack.js"></script>
|
<script src="/js/highlight.pack.js"></script>
|
||||||
|
|
|
@ -1,22 +1,5 @@
|
||||||
/* Insert here special css for hugo theme, on top of any other imported css */
|
/* Insert here special css for hugo theme, on top of any other imported css */
|
||||||
|
|
||||||
/*
|
|
||||||
.progress {
|
|
||||||
position: relative;
|
|
||||||
float: top;
|
|
||||||
text-align: left;
|
|
||||||
width: 330px;
|
|
||||||
padding: 45px 0 0 2%;
|
|
||||||
}
|
|
||||||
.progress .wrapper {
|
|
||||||
position: absolute;
|
|
||||||
width: inherit;
|
|
||||||
}
|
|
||||||
.progress .wrapper.affix {
|
|
||||||
position: fixed;
|
|
||||||
top: 10px;
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/* Table of contents */
|
/* Table of contents */
|
||||||
|
|
||||||
|
@ -53,3 +36,11 @@
|
||||||
padding-right: 1rem !important;
|
padding-right: 1rem !important;
|
||||||
margin-right: 0.5rem !important;
|
margin-right: 0.5rem !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#top-bar {
|
||||||
|
z-index: 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
#top-bar.is_stuck {
|
||||||
|
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
|
@ -62,3 +62,5 @@ $('#toc-menu').hover(function() {
|
||||||
$('.progress').hover(function() {
|
$('.progress').hover(function() {
|
||||||
$('.progress').stop(true, false, true).fadeToggle(300);
|
$('.progress').stop(true, false, true).fadeToggle(300);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#top-bar").stick_in_parent();
|
||||||
|
|
9
static/js/jquery.sticky-kit.min.js
vendored
Normal file
9
static/js/jquery.sticky-kit.min.js
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
/*
|
||||||
|
Sticky-kit v1.1.2 | WTFPL | Leaf Corcoran 2015 | http://leafo.net
|
||||||
|
*/
|
||||||
|
(function(){var b,f;b=this.jQuery||window.jQuery;f=b(window);b.fn.stick_in_parent=function(d){var A,w,J,n,B,K,p,q,k,E,t;null==d&&(d={});t=d.sticky_class;B=d.inner_scrolling;E=d.recalc_every;k=d.parent;q=d.offset_top;p=d.spacer;w=d.bottoming;null==q&&(q=0);null==k&&(k=void 0);null==B&&(B=!0);null==t&&(t="is_stuck");A=b(document);null==w&&(w=!0);J=function(a,d,n,C,F,u,r,G){var v,H,m,D,I,c,g,x,y,z,h,l;if(!a.data("sticky_kit")){a.data("sticky_kit",!0);I=A.height();g=a.parent();null!=k&&(g=g.closest(k));
|
||||||
|
if(!g.length)throw"failed to find stick parent";v=m=!1;(h=null!=p?p&&a.closest(p):b("<div />"))&&h.css("position",a.css("position"));x=function(){var c,f,e;if(!G&&(I=A.height(),c=parseInt(g.css("border-top-width"),10),f=parseInt(g.css("padding-top"),10),d=parseInt(g.css("padding-bottom"),10),n=g.offset().top+c+f,C=g.height(),m&&(v=m=!1,null==p&&(a.insertAfter(h),h.detach()),a.css({position:"",top:"",width:"",bottom:""}).removeClass(t),e=!0),F=a.offset().top-(parseInt(a.css("margin-top"),10)||0)-q,
|
||||||
|
u=a.outerHeight(!0),r=a.css("float"),h&&h.css({width:a.outerWidth(!0),height:u,display:a.css("display"),"vertical-align":a.css("vertical-align"),"float":r}),e))return l()};x();if(u!==C)return D=void 0,c=q,z=E,l=function(){var b,l,e,k;if(!G&&(e=!1,null!=z&&(--z,0>=z&&(z=E,x(),e=!0)),e||A.height()===I||x(),e=f.scrollTop(),null!=D&&(l=e-D),D=e,m?(w&&(k=e+u+c>C+n,v&&!k&&(v=!1,a.css({position:"fixed",bottom:"",top:c}).trigger("sticky_kit:unbottom"))),e<F&&(m=!1,c=q,null==p&&("left"!==r&&"right"!==r||a.insertAfter(h),
|
||||||
|
h.detach()),b={position:"",width:"",top:""},a.css(b).removeClass(t).trigger("sticky_kit:unstick")),B&&(b=f.height(),u+q>b&&!v&&(c-=l,c=Math.max(b-u,c),c=Math.min(q,c),m&&a.css({top:c+"px"})))):e>F&&(m=!0,b={position:"fixed",top:c},b.width="border-box"===a.css("box-sizing")?a.outerWidth()+"px":a.width()+"px",a.css(b).addClass(t),null==p&&(a.after(h),"left"!==r&&"right"!==r||h.append(a)),a.trigger("sticky_kit:stick")),m&&w&&(null==k&&(k=e+u+c>C+n),!v&&k)))return v=!0,"static"===g.css("position")&&g.css({position:"relative"}),
|
||||||
|
a.css({position:"absolute",bottom:d,top:"auto"}).trigger("sticky_kit:bottom")},y=function(){x();return l()},H=function(){G=!0;f.off("touchmove",l);f.off("scroll",l);f.off("resize",y);b(document.body).off("sticky_kit:recalc",y);a.off("sticky_kit:detach",H);a.removeData("sticky_kit");a.css({position:"",bottom:"",top:"",width:""});g.position("position","");if(m)return null==p&&("left"!==r&&"right"!==r||a.insertAfter(h),h.remove()),a.removeClass(t)},f.on("touchmove",l),f.on("scroll",l),f.on("resize",
|
||||||
|
y),b(document.body).on("sticky_kit:recalc",y),a.on("sticky_kit:detach",H),setTimeout(l,0)}};n=0;for(K=this.length;n<K;n++)d=this[n],J(b(d));return this}}).call(this);
|
Loading…
Reference in a new issue