window.onload = function() { // 屏幕高度,浏览器窗口大小改变,屏幕高度不变 let screenHeight = $(document).height(); // 页面高度,也叫窗口高度,随浏览器窗口大小改变而改变 let windowHeight = $(this).height(); // 垂直滚动的距离,即当前滚动的地方的窗口顶端到整个页面顶端的距离 let scrollTop = Math.round($(this).scrollTop()); // footer 元素高度,包括 height + padding let footerHeight = $('#footer').innerHeight(); // 若不考虑footer,页面滚动到底部的时候,scrollTop + windowHeight = screenHeight let bottomOffset = screenHeight - (scrollTop + windowHeight); $('#sidebar').css('bottom', '0px'); } (function($) { "use strict"; // Clipboard 复制成功后,弹出 success modal 闪现一下 $.flashClip = function() { $('#clipModClipIcon').show(); $('#clipModCheckIcon').hide(); $('#clipModal').modal('show'); } $('#clipModal').on('shown.bs.modal', function (e) { $('#clipModClipIcon').fadeOut(200, function() { $('#clipModCheckIcon').fadeIn(100); }); setTimeout(function() { $('#clipModal').modal('hide'); }, 800); }); }(jQuery)); /* DOM结构绘制完毕后就执行 */ $(document).ready(function() { /* -------------------------------------------------- * 导航栏 * -------------------------------------------------- */ (function() { // Metis 导航栏初始化 $('#metisMenu').metisMenu({ toggle: true }); $('#metisMenu').find('a.anchorPanel').on('click', function() { $('#metisMenu').find('.mm-active').removeClass('mm-active'); $(this).parent().addClass('mm-active'); $('#paperclipIcon').remove(); $($(this).attr('href')).children().first().prepend( $('').addClass('bi bi-paperclip fs-3 text-danger').attr('id', 'paperclipIcon').html(" ") ); }); $('#metisMenu').find('a.anchorElm').on('click', function() { $('#metisMenu').find('.mm-active').removeClass('mm-active'); $(this).parent().addClass('mm-active'); $(this).parent().parent().parent().addClass('mm-active'); $('#paperclipIcon').remove(); $($(this).attr('href')).prepend( $('').addClass('bi bi-paperclip fs-4 text-danger').attr('id', 'paperclipIcon').html(" ") ); }); // 手机端侧边导航栏切换,仅显示或隐藏 sidebar,主内容宽度不变 $('#sidebarToggleBtn').on('click', function() { let animateIn = 'animate__animated animate__fadeInLeft animate__faster'; let animateOut = 'animate__animated animate__fadeOutLeft animate__faster'; if ($('#sidebar').hasClass('phone-active')) { $('#sidebar').addClass(animateOut).on('animationend', function() { $('#sidebar').removeClass(animateOut + ' phone-active').unbind(); }); $('#coverRag').remove(); } else { $('#sidebar').addClass(animateIn + ' phone-active').on('animationend', function() { $('#sidebar').removeClass(animateIn).addClass('phone-active').unbind(); }); $('body').append( $('
').addClass('cover-rag').attr('id', 'coverRag').on('click', function() { $('#sidebar').addClass(animateOut).on('animationend', function() { $('#sidebar').removeClass(animateOut + ' phone-active').unbind(); }); $('#coverRag').remove(); }) ); } }); })(); /* -------------------------------------------------- * 页面滑动到底部时,调整 #sidebar bottom,使 footer 能显示完整 * -------------------------------------------------- */ $(window).scroll(function() { // 屏幕高度,浏览器窗口大小改变,屏幕高度不变 let screenHeight = $(document).height(); // 页面高度,也叫窗口高度,随浏览器窗口大小改变而改变 let windowHeight = $(this).height(); // 垂直滚动的距离,即当前滚动的地方的窗口顶端到整个页面顶端的距离 let scrollTop = Math.round($(this).scrollTop()); // footer 元素高度,包括 height + padding let footerHeight = $('#footer').innerHeight(); $('#sidebar').css('bottom', '0px'); /*// 若不考虑footer,页面滚动到底部的时候,scrollTop + windowHeight = screenHeight let bottomOffset = screenHeight - (scrollTop + windowHeight); if (bottomOffset > footerHeight) { if ($('#sidebar').css('bottom') != '0px') { $('#sidebar').css('bottom', '0px'); } } else { $('#sidebar').css('bottom', (footerHeight - bottomOffset) + 'px'); }*/ }); (function($, window, document, undefined) { "use strict"; // 统一初始化术语 tooltip $('.glossary').tooltip(); /* -------------------------------------------------- * Scoll to Top 按钮 * -------------------------------------------------- */ $.gototop = function(el, options) { let SCROLL = 0; let PAGE = $("html, body"); let base = this; base.$el = $(el); base.el = el; base.$el.data('gototop', base); base.initialize = function () { base.options = $.extend({}, $.gototop.defaultOptions, options); base.listen(); base.getScrollPosition(); }; base.listen = function () { window.addEventListener("scroll", base.getScrollPosition, false); base.$el.on("click", { position: base.options.position, duration: base.options.duration }, base.scrolltotop); }; base.getScrollPosition = function () { SCROLL = document.body.scrollTop || window.pageYOffset; base.checkPosition(); }; base.checkPosition = function () { if (SCROLL >= base.options.visibleAt) { base.$el.fadeIn('slow'); } else { base.$el.fadeOut('fast'); } }; base.scrolltotop = function (event) { PAGE.animate({ scrollTop: event.data.position }, event.data.duration); }; base.initialize(); }; $.gototop.defaultOptions = { // 上滚至离顶部的位置,0表示最顶部 position: 0, // 上滚时长,毫秒 duration: 300, // 向下滚动超过 visibleAt 则显示按钮 visibleAt: 20 }; $.fn.gototop = function (options) { return this.each(function () { var gototop = new $.gototop(this, options); }); }; $("#goToTop").gototop(); }(jQuery, window, document)); });