text: function scrollToElement(target, offset) {
    var scroll_offset = $(target).offset();
    $('body,html').animate({
      scrollTop: scroll_offset.top + (offset || 0),
      easing: 'swing',
    });
  }
  
  function scrollToBoard() {
    scrollToElement('#board', -$('#navbar').height());
  }
  
  // 防抖动函数
  function debounce(func, wait, immediate) {
    var timeout;
    return function () {
      var context = this, args = arguments;
      var later = function () {
        timeout = null;
        if (!immediate) func.apply(context, args);
      };
      var callNow = immediate && !timeout;
      clearTimeout(timeout);
      timeout = setTimeout(later, wait);
      if (callNow) func.apply(context, args);
    };
  }
  
  $(document).ready(function () {
    // 顶部菜单的动效
    var navbar = $('#navbar');
    if (navbar.offset().top > 0) {
      navbar.addClass('navbar-custom');
      navbar.removeClass('navbar-dark');
    }
    $(window).scroll(function () {
      $('.scrolling-navbar')[navbar.offset().top > 50 ? 'addClass' : 'removeClass']('top-nav-collapse');
      if (navbar.offset().top > 0) {
        navbar.addClass('navbar-custom');
        navbar.removeClass('navbar-dark');
      } else {
        navbar.addClass('navbar-dark');
      }
    });
    $('#navbar-toggler-btn').on('click', function () {
      $('.animated-icon').toggleClass('open');
      $('#navbar').toggleClass('navbar-col-show');
    });
  
    // 头图视差动画
    var target = $('#background[parallax="true"]');
    var parallax = function () {
      var oVal = $(window).scrollTop() / 5;
      var offset = parseInt($('#board').css('margin-top'));
      var max = 96 + offset;
      if (oVal > max) {
        oVal = max;
      }
      target.css({
        transform: 'translate3d(0,' + oVal + 'px,0)',
        '-webkit-transform': 'translate3d(0,' + oVal + 'px,0)',
        '-ms-transform': 'translate3d(0,' + oVal + 'px,0)',
        '-o-transform': 'translate3d(0,' + oVal + 'px,0)',
      });
  
      var toc = $('#toc');
      if (toc) {
        $('#toc-ctn').css({
          'padding-top': oVal + 'px',
        });
      }
    };
    if (target.length > 0) {
      parallax();
      $(window).scroll(parallax);
    }
  
    // 向下滚动箭头的点击
    $('.scroll-down-bar').on('click', scrollToBoard);
  
    // 向顶部滚动箭头
    var topArrow = $('#scroll-top-button');
    var posDisplay = false;
    var scrollDisplay = false;
    // 位置
    var setTopArrowPos = function () {
      var boardRight = document.getElementById('board').getClientRects()[0].right;
      var bodyWidth = document.body.offsetWidth;
      var right = bodyWidth - boardRight;
      posDisplay = right >= 50;
      topArrow.css({
        'bottom': posDisplay && scrollDisplay ? '20px' : '-60px',
        'right': right - 64 + 'px',
      });
    };
    setTopArrowPos();
    $(window).resize(setTopArrowPos);
    // 显示
    var headerHeight = $('#board').offset().top;
    $(window).scroll(debounce(function () {
      var scrollHeight = document.body.scrollTop + document.documentElement.scrollTop;
      scrollDisplay = scrollHeight >= headerHeight;
      topArrow.css({
        'bottom': posDisplay && scrollDisplay ? '20px' : '-60px',
      });
    }, 20));
    // 点击
    topArrow.on('click', function () {
      $('body,html').animate({
        scrollTop: 0,
        easing: 'swing',
      });
    });
  });
  