mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-16 20:30:53 +08:00
label: 3.4.0 發佈
improvement: js優化
This commit is contained in:
@@ -383,9 +383,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
const contentMath = (docHeight > winHeight) ? (docHeight - winHeight) : (document.documentElement.scrollHeight - winHeight)
|
||||
const scrollPercent = (currentTop - headerHeight) / (contentMath)
|
||||
const scrollPercentRounded = Math.round(scrollPercent * 100)
|
||||
const percentage = (scrollPercentRounded > 100) ? 100
|
||||
: (scrollPercentRounded <= 0) ? 0
|
||||
: scrollPercentRounded
|
||||
const percentage = (scrollPercentRounded > 100) ? 100 : (scrollPercentRounded <= 0) ? 0 : scrollPercentRounded
|
||||
$cardToc.setAttribute('progress-percentage', percentage)
|
||||
}
|
||||
|
||||
@@ -687,7 +685,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
|
||||
if (!$tabItem.classList.contains('active')) {
|
||||
const $tabContent = $tabItem.parentNode.nextElementSibling
|
||||
btf.siblings($tabItem, 'active')[0].classList.remove('active')
|
||||
btf.siblings($tabItem, '.active')[0].classList.remove('active')
|
||||
$tabItem.classList.add('active')
|
||||
const tabId = $this.getAttribute('data-href').replace('#', '')
|
||||
const childList = [...$tabContent.children]
|
||||
@@ -753,7 +751,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
|
||||
const addPostOutdateNotice = function () {
|
||||
const data = GLOBAL_CONFIG.noticeOutdate
|
||||
var diffDay = btf.diffDate(GLOBAL_CONFIG_SITE.postUpdate)
|
||||
const diffDay = btf.diffDate(GLOBAL_CONFIG_SITE.postUpdate)
|
||||
if (diffDay >= data.limitDay) {
|
||||
const ele = document.createElement('div')
|
||||
ele.className = 'post-outdate-notice'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var btf = {
|
||||
const btf = {
|
||||
debounce: function (func, wait, immediate) {
|
||||
let timeout
|
||||
return function () {
|
||||
@@ -140,7 +140,7 @@ var btf = {
|
||||
return
|
||||
}
|
||||
|
||||
var currentPos = window.scrollY || window.screenTop
|
||||
const currentPos = window.scrollY || window.screenTop
|
||||
if (currentPos > pos) pos = pos - 70
|
||||
|
||||
if ('CSS' in window && CSS.supports('scroll-behavior', 'smooth')) {
|
||||
@@ -151,7 +151,7 @@ var btf = {
|
||||
return
|
||||
}
|
||||
|
||||
var start = null
|
||||
let start = null
|
||||
time = time || 500
|
||||
window.requestAnimationFrame(function step (currentTime) {
|
||||
start = !start ? currentTime : start
|
||||
@@ -188,38 +188,18 @@ var btf = {
|
||||
},
|
||||
|
||||
getParents: (elem, selector) => {
|
||||
// polyfill
|
||||
if (!Element.prototype.matches) {
|
||||
Element.prototype.matches =
|
||||
Element.prototype.matchesSelector ||
|
||||
Element.prototype.mozMatchesSelector ||
|
||||
Element.prototype.msMatchesSelector ||
|
||||
Element.prototype.oMatchesSelector ||
|
||||
Element.prototype.webkitMatchesSelector ||
|
||||
function (s) {
|
||||
const matches = (this.document || this.ownerDocument).querySelectorAll(s)
|
||||
let i = matches.length
|
||||
while (--i >= 0 && matches.item(i) !== this) {}
|
||||
return i > -1
|
||||
}
|
||||
}
|
||||
|
||||
for (; elem && elem !== document; elem = elem.parentNode) {
|
||||
if (elem.matches(selector)) return elem
|
||||
}
|
||||
return null
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} ele
|
||||
* @param {*} selector class name
|
||||
*/
|
||||
siblings: (ele, selector) => {
|
||||
return [...ele.parentNode.children].filter((child) => {
|
||||
if (selector) {
|
||||
return child !== ele && child.classList.contains(selector)
|
||||
return child !== ele && child.matches(selector)
|
||||
}
|
||||
return child !== ele
|
||||
})
|
||||
},
|
||||
|
||||
@@ -230,7 +210,7 @@ var btf = {
|
||||
* @param {*} id id
|
||||
* @param {*} cn class name
|
||||
*/
|
||||
wrap: function (selector, eleType, id = null, cn = null) {
|
||||
wrap: function (selector, eleType, id = '', cn = '') {
|
||||
const creatEle = document.createElement(eleType)
|
||||
if (id) creatEle.id = id
|
||||
if (cn) creatEle.className = cn
|
||||
|
||||
Reference in New Issue
Block a user