// ..\layout\_partial\extra\toc_action.ejs
// 底部添加快速导航开关图标(移动设备上可关闭,不影响阅读)
<div id="menu-nav" class="footer-btn">
<a title="<%= __('quick_nav') %>"><img src="/img/list.png"/></a>
</div>
<script type="text/javascript">
$(function(){
var toc = $('#toc');
var nav = $('#menu-nav');
var toccopy;
var status = true;
if ($(window).width() <= 583)
status = false;
var first = true;
var position = toc.position();
var wid = toc.width();
$(window).scroll(onScroll);
$(nav).click(opennav);
function tocout() {
if (first && status) {
toccopy = $(toc).clone();
$(toccopy).insertAfter(toc);
toc.css('float','');
toc.css('position','fixed');
onResize();
toc.css('z-index','99');
toc.css('width',wid);
$(window).resize(onResize);
first = false;
toccopy.css('visibility', 'hidden');
}
}
function onScroll() {
var top = $(window).scrollTop();
if(top >= position.top + 30){
tocout();
$(nav).stop().fadeTo(300, 1);
$(nav).animate({bottom: "25px"}, { queue: false, duration: 10 });
}else{
hidNav();
$(window).off("resize", onResize);
$(nav).stop().fadeTo(300, 0);
$(nav).animate({bottom: "-200px"}, { queue: false, duration: 10 });
}
}
function onResize() {
var width = $(window).width();
var left = $('#sidebar').position().left;
if (width > 883){
toc.css('top', '88px');
toc.css('left', left - 18);
} else{
var top = $('#nav-top').innerHeight();
toc.css('top', top);
var fix = $('#main-col').width() - toc.width() - 35;
toc.css('left', left + fix);
if($(window).scrollTop() >= position.top + 30){
$(nav).stop().fadeTo(300, 1);
$(nav).animate({bottom: "25px"}, { queue: false, duration: 10 });
}
}
}
function hidNav() {
toc.css('position','');
toc.css('float','right');
$(toccopy).remove();
first = true;
}
function opennav() {
if (status) {
status = false;
hidNav();
} else {
status = true;
tocout();
}
}
});
</script>