window.Joe = function () { /* 解决移动端Hover问题 */ { document.addEventListener('touchstart', () => {}) } /* 激活全局下拉框功能 */ { $('.joe_dropdown').each(function (index, item) { const menu = $(this).find('.joe_dropdown__menu') /* 弹出方式 */ const trigger = $(item).attr('trigger') || 'click' /* 弹出高度 */ const placement = $(item).attr('placement') || $(this).height() || 0 /* 设置弹出高度 */ menu.css('top', placement) /* 如果是hover,则绑定hover事件 */ if (trigger === 'hover') { $(this).hover( () => $(this).addClass('active'), () => $(this).removeClass('active') ) } else { /* 否则绑定点击事件 */ $(this).on('click', function (e) { $(this).toggleClass('active') $(document).one('click', () => $(this).removeClass('active')) e.stopPropagation() }) menu.on('click', e => e.stopPropagation()) } }) } /* 激活全局返回顶部功能 */ { const handleScroll = () => { let scrollTop = document.documentElement.scrollTop || document.body.scrollTop scrollTop > 300 ? $('.joe_action .joe_action_item.scroll').addClass('active') : $('.joe_action .joe_action_item.scroll').removeClass('active') } handleScroll() $(window).on('scroll', () => handleScroll()) $('.joe_action .joe_action_item.scroll').on('click', () => window.scrollTo({ top: 0, behavior: 'smooth' })) } /* 激活侧边栏人生倒计时功能 */ { if ($('.joe_aside__item.timelife').length !== 0) { let timelife = [ { title: '今日已经过去', endTitle: '小时', num: 0, percent: '0%' }, { title: '这周已经过去', endTitle: '天', num: 0, percent: '0%' }, { title: '本月已经过去', endTitle: '天', num: 0, percent: '0%' }, { title: '今年已经过去', endTitle: '个月', num: 0, percent: '0%' } ] { let nowDate = +new Date() let todayStartDate = new Date(new Date().toLocaleDateString()).getTime() let todayPassHours = (nowDate - todayStartDate) / 1000 / 60 / 60 let todayPassHoursPercent = (todayPassHours / 24) * 100 timelife[0].num = parseInt(todayPassHours) timelife[0].percent = parseInt(todayPassHoursPercent) + '%' } { let weeks = { 0: 7, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6 } let weekDay = weeks[new Date().getDay()] let weekDayPassPercent = (weekDay / 7) * 100 timelife[1].num = parseInt(weekDay) timelife[1].percent = parseInt(weekDayPassPercent) + '%' } { let year = new Date().getFullYear() let date = new Date().getDate() let month = new Date().getMonth() + 1 let monthAll = new Date(year, month, 0).getDate() let monthPassPercent = (date / monthAll) * 100 timelife[2].num = date timelife[2].percent = parseInt(monthPassPercent) + '%' } { let month = new Date().getMonth() + 1 let yearPass = (month / 12) * 100 timelife[3].num = month timelife[3].percent = parseInt(yearPass) + '%' } let htmlStr = '' timelife.forEach((item, index) => { htmlStr += `