mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-17 04:40:53 +08:00
label: 3.4.0 發佈
improvement: js優化
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hexo-theme-butterfly",
|
"name": "hexo-theme-butterfly",
|
||||||
"version": "3.4.0-b6",
|
"version": "3.4.0",
|
||||||
"description": "A Simple and Card UI Design theme for Hexo",
|
"description": "A Simple and Card UI Design theme for Hexo",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.1 KiB |
@@ -383,9 +383,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
const contentMath = (docHeight > winHeight) ? (docHeight - winHeight) : (document.documentElement.scrollHeight - winHeight)
|
const contentMath = (docHeight > winHeight) ? (docHeight - winHeight) : (document.documentElement.scrollHeight - winHeight)
|
||||||
const scrollPercent = (currentTop - headerHeight) / (contentMath)
|
const scrollPercent = (currentTop - headerHeight) / (contentMath)
|
||||||
const scrollPercentRounded = Math.round(scrollPercent * 100)
|
const scrollPercentRounded = Math.round(scrollPercent * 100)
|
||||||
const percentage = (scrollPercentRounded > 100) ? 100
|
const percentage = (scrollPercentRounded > 100) ? 100 : (scrollPercentRounded <= 0) ? 0 : scrollPercentRounded
|
||||||
: (scrollPercentRounded <= 0) ? 0
|
|
||||||
: scrollPercentRounded
|
|
||||||
$cardToc.setAttribute('progress-percentage', percentage)
|
$cardToc.setAttribute('progress-percentage', percentage)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -687,7 +685,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
|
|
||||||
if (!$tabItem.classList.contains('active')) {
|
if (!$tabItem.classList.contains('active')) {
|
||||||
const $tabContent = $tabItem.parentNode.nextElementSibling
|
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')
|
$tabItem.classList.add('active')
|
||||||
const tabId = $this.getAttribute('data-href').replace('#', '')
|
const tabId = $this.getAttribute('data-href').replace('#', '')
|
||||||
const childList = [...$tabContent.children]
|
const childList = [...$tabContent.children]
|
||||||
@@ -753,7 +751,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
|||||||
|
|
||||||
const addPostOutdateNotice = function () {
|
const addPostOutdateNotice = function () {
|
||||||
const data = GLOBAL_CONFIG.noticeOutdate
|
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) {
|
if (diffDay >= data.limitDay) {
|
||||||
const ele = document.createElement('div')
|
const ele = document.createElement('div')
|
||||||
ele.className = 'post-outdate-notice'
|
ele.className = 'post-outdate-notice'
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
var btf = {
|
const btf = {
|
||||||
debounce: function (func, wait, immediate) {
|
debounce: function (func, wait, immediate) {
|
||||||
let timeout
|
let timeout
|
||||||
return function () {
|
return function () {
|
||||||
@@ -140,7 +140,7 @@ var btf = {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentPos = window.scrollY || window.screenTop
|
const currentPos = window.scrollY || window.screenTop
|
||||||
if (currentPos > pos) pos = pos - 70
|
if (currentPos > pos) pos = pos - 70
|
||||||
|
|
||||||
if ('CSS' in window && CSS.supports('scroll-behavior', 'smooth')) {
|
if ('CSS' in window && CSS.supports('scroll-behavior', 'smooth')) {
|
||||||
@@ -151,7 +151,7 @@ var btf = {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var start = null
|
let start = null
|
||||||
time = time || 500
|
time = time || 500
|
||||||
window.requestAnimationFrame(function step (currentTime) {
|
window.requestAnimationFrame(function step (currentTime) {
|
||||||
start = !start ? currentTime : start
|
start = !start ? currentTime : start
|
||||||
@@ -188,38 +188,18 @@ var btf = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
getParents: (elem, selector) => {
|
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) {
|
for (; elem && elem !== document; elem = elem.parentNode) {
|
||||||
if (elem.matches(selector)) return elem
|
if (elem.matches(selector)) return elem
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {*} ele
|
|
||||||
* @param {*} selector class name
|
|
||||||
*/
|
|
||||||
siblings: (ele, selector) => {
|
siblings: (ele, selector) => {
|
||||||
return [...ele.parentNode.children].filter((child) => {
|
return [...ele.parentNode.children].filter((child) => {
|
||||||
if (selector) {
|
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 {*} id id
|
||||||
* @param {*} cn class name
|
* @param {*} cn class name
|
||||||
*/
|
*/
|
||||||
wrap: function (selector, eleType, id = null, cn = null) {
|
wrap: function (selector, eleType, id = '', cn = '') {
|
||||||
const creatEle = document.createElement(eleType)
|
const creatEle = document.createElement(eleType)
|
||||||
if (id) creatEle.id = id
|
if (id) creatEle.id = id
|
||||||
if (cn) creatEle.className = cn
|
if (cn) creatEle.className = cn
|
||||||
|
|||||||
Reference in New Issue
Block a user