console.time("Index.js执行时长") document.addEventListener('DOMContentLoaded', () => { /* 激活轮播图功能 */ { if ($('.joe_index__banner .swiper-container').length !== 0) { let direction = 'horizontal' if (!Joe.IS_MOBILE && $('.joe_index__banner-recommend .item').length === 2) direction = 'vertical' new Swiper('.swiper-container', { keyboard: true, direction, loop: true, autoplay: true, mousewheel: true, pagination: { el: '.swiper-pagination' } }) } } /* 初始化首页列表功能 */ { let queryData = { page: 1, pageSize: 10, type: 'created' } const initDom = () => { $('.joe_index__list .joe_list').html('') let activeItem = $('.joe_index__title-title .item[data-type="' + queryData.type + '"]') let activeLine = $('.joe_index__title-title .line') activeItem.addClass('active').siblings().removeClass('active') activeLine.css({ left: activeItem.position().left, width: activeItem.width() }) } const pushDom = () => { return new Promise((reslove, reject) => { $('.joe_load').attr('loading', true) $('.joe_load').html('加载中') $('.joe_index__list .joe_list__loading').show() $.ajax({ url: Joe.BASE_API, type: 'POST', data: { routeType: 'publish_list', page: queryData.page, pageSize: queryData.pageSize, type: queryData.type }, success(res) { if (res.data.length === 0) { $('.joe_load').remove() $('.joe_index__list .joe_list__loading').hide() return } res.data.forEach(_ => { $('.joe_index__list .joe_list').append(`
  • ${_.title}
    ${_.title}
    ${_.abstract}
    • ${_.created}
    • ${_.views} 阅读
    • ${_.commentsNum} 评论
    • ${_.agree} 点赞
  • `) }) $('.joe_load').removeAttr('loading') $('.joe_load').html('查看更多') $('.joe_index__list .joe_list__loading').hide() new LazyLoad('.list_lazyload') reslove(res.data.length > 0 ? res.data.length - 1 : 0) } }) }) } initDom() pushDom() $('.joe_index__title-title .item').on('click', async function () { if ($(this).attr('data-type') === queryData.type) return queryData = { page: 1, pageSize: 10, type: $(this).attr('data-type') } initDom() pushDom() }) $('.joe_load').on('click', async function () { if ($(this).attr('loading')) return queryData.page++ let length = await pushDom() length = $('.joe_index__list .joe_list .joe_list__item').length - length const queryElement = `.joe_index__list .joe_list .joe_list__item:nth-child(${length})` const offset = $(queryElement).offset().top - $('.joe_header').height() window.scrollTo({ top: offset - 15, behavior: 'smooth' }) }) } /* 激活列表特效 */ { const wow = $('.joe_index__list').attr('data-wow') if (wow !== 'off' && wow) new WOW({ boxClass: 'wow', animateClass: `animated ${wow}`, offset: 0, mobile: true, live: true, scrollContainer: null }).init() } console.timeEnd("Index.js执行时长") })