-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
97 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,35 @@ | ||
Element.prototype.siblings = function () { | ||
const siblingElement = [] | ||
const sibs = this.parentNode.children | ||
for (let i = 0; i < sibs.length; i++) { | ||
if (sibs[i] !== this) { | ||
siblingElement.push(sibs[i]) | ||
(function () { | ||
Element.prototype.siblings = function () { | ||
const siblingElement = [] | ||
const sibs = this.parentNode.children | ||
for (let i = 0; i < sibs.length; i++) { | ||
if (sibs[i] !== this) { | ||
siblingElement.push(sibs[i]) | ||
} | ||
} | ||
return siblingElement | ||
} | ||
return siblingElement | ||
} | ||
function tabClick () { | ||
// 修改标签样式 | ||
this.classList.add('bangumi-active') | ||
let sibs = this.siblings() | ||
for (let j = 0; j < sibs.length; j++) { | ||
sibs[j].classList.remove('bangumi-active') | ||
function tabClick() { | ||
// 修改标签样式 | ||
this.classList.add('bangumi-active') | ||
let sibs = this.siblings() | ||
for (let j = 0; j < sibs.length; j++) { | ||
sibs[j].classList.remove('bangumi-active') | ||
} | ||
// 显示对应板块 | ||
const itemId = this.id.replace('tab', 'item') | ||
const target = document.getElementById(itemId) | ||
target.classList.remove('bangumi-hide') | ||
target.classList.add('bangumi-show') | ||
sibs = document.getElementById(itemId).siblings() | ||
for (let k = 0; k < sibs.length; k++) { | ||
sibs[k].classList.remove('bangumi-show') | ||
sibs[k].classList.add('bangumi-hide') | ||
} | ||
} | ||
// 显示对应板块 | ||
const itemId = this.id.replace('tab', 'item') | ||
const target = document.getElementById(itemId) | ||
target.classList.remove('bangumi-hide') | ||
target.classList.add('bangumi-show') | ||
sibs = document.getElementById(itemId).siblings() | ||
for (let k = 0; k < sibs.length; k++) { | ||
sibs[k].classList.remove('bangumi-show') | ||
sibs[k].classList.add('bangumi-hide') | ||
const tabs = document.getElementsByClassName('bangumi-tab') | ||
for (let i = 0; i < tabs.length; i++) { | ||
tabs[i].onclick = tabClick | ||
tabs[i].onclick.apply(tabs[i]) | ||
} | ||
} | ||
const tabs = document.getElementsByClassName('bangumi-tab') | ||
for (let i = 0; i < tabs.length; i++) { | ||
tabs[i].onclick = tabClick | ||
tabs[i].onclick.apply(tabs[i]) | ||
} | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,72 @@ | ||
var firstpages = document.getElementsByClassName('bangumi-firstpage') | ||
var previouspages = document.getElementsByClassName('bangumi-previouspage') | ||
var nextpages = document.getElementsByClassName('bangumi-nextpage') | ||
var lastpages = document.getElementsByClassName('bangumi-lastpage') | ||
var pagenums = document.getElementsByClassName('bangumi-pagenum') | ||
(function () { | ||
const firstpages = document.getElementsByClassName('bangumi-firstpage') | ||
const previouspages = document.getElementsByClassName('bangumi-previouspage') | ||
const nextpages = document.getElementsByClassName('bangumi-nextpage') | ||
const lastpages = document.getElementsByClassName('bangumi-lastpage') | ||
const pagenums = document.getElementsByClassName('bangumi-pagenum') | ||
|
||
function makePageNum (num, arr) { | ||
return (num + 1) + ' / ' + (Math.ceil(arr.length / 10 === 0 ? 1 : Math.ceil(arr.length / 10))) | ||
} | ||
function makePageNum(num, arr) { | ||
return (num + 1) + ' / ' + (Math.ceil(arr.length / 10 === 0 ? 1 : Math.ceil(arr.length / 10))) | ||
} | ||
|
||
function firstBtn () { | ||
var sibs = this.parentNode.siblings() | ||
displayPage(sibs, 0) | ||
this.parentNode.getElementsByClassName('bangumi-pagenum')[0].innerText = makePageNum(0, sibs) | ||
} | ||
function firstBtn() { | ||
const sibs = this.parentNode.siblings() | ||
displayPage(sibs, 0) | ||
this.parentNode.getElementsByClassName('bangumi-pagenum')[0].innerText = makePageNum(0, sibs) | ||
} | ||
|
||
function previousBtn () { | ||
var sibs = this.parentNode.siblings() | ||
var currNum = this.parentNode.getElementsByClassName('bangumi-pagenum')[0].innerText | ||
currNum = currNum.substr(0, currNum.indexOf('/') - 1) | ||
currNum = parseInt(currNum, 10) - 1 | ||
if (currNum > 0) { | ||
currNum-- | ||
function previousBtn() { | ||
const sibs = this.parentNode.siblings() | ||
let currNum = this.parentNode.getElementsByClassName('bangumi-pagenum')[0].innerText | ||
currNum = currNum.substr(0, currNum.indexOf('/') - 1) | ||
currNum = parseInt(currNum, 10) - 1 | ||
if (currNum > 0) { | ||
currNum-- | ||
} | ||
displayPage(sibs, currNum) | ||
this.parentNode.getElementsByClassName('bangumi-pagenum')[0].innerText = makePageNum(currNum, sibs) | ||
} | ||
displayPage(sibs, currNum) | ||
this.parentNode.getElementsByClassName('bangumi-pagenum')[0].innerText = makePageNum(currNum, sibs) | ||
} | ||
|
||
function nextBtn () { | ||
var sibs = this.parentNode.siblings() | ||
var currNum = this.parentNode.getElementsByClassName('bangumi-pagenum')[0].innerText | ||
currNum = currNum.substr(0, currNum.indexOf('/') - 1) | ||
currNum = parseInt(currNum, 10) - 1 | ||
if (currNum < Math.ceil(sibs.length / 10) - 1) { | ||
currNum++ | ||
function nextBtn() { | ||
const sibs = this.parentNode.siblings() | ||
let currNum = this.parentNode.getElementsByClassName('bangumi-pagenum')[0].innerText | ||
currNum = currNum.substr(0, currNum.indexOf('/') - 1) | ||
currNum = parseInt(currNum, 10) - 1 | ||
if (currNum < Math.ceil(sibs.length / 10) - 1) { | ||
currNum++ | ||
} | ||
displayPage(sibs, currNum) | ||
this.parentNode.getElementsByClassName('bangumi-pagenum')[0].innerText = makePageNum(currNum, sibs) | ||
} | ||
displayPage(sibs, currNum) | ||
this.parentNode.getElementsByClassName('bangumi-pagenum')[0].innerText = makePageNum(currNum, sibs) | ||
} | ||
|
||
function lastBtn () { | ||
var sibs = this.parentNode.siblings() | ||
displayPage(sibs, Math.ceil(sibs.length / 10) - 1) | ||
this.parentNode.getElementsByClassName('bangumi-pagenum')[0].innerText = makePageNum(Math.ceil(sibs.length / 10) - 1 === -1 ? 0 : Math.ceil(sibs.length / 10) - 1, sibs) | ||
} | ||
function lastBtn() { | ||
const sibs = this.parentNode.siblings() | ||
displayPage(sibs, Math.ceil(sibs.length / 10) - 1) | ||
this.parentNode.getElementsByClassName('bangumi-pagenum')[0].innerText = makePageNum(Math.ceil(sibs.length / 10) - 1 === -1 ? 0 : Math.ceil(sibs.length / 10) - 1, sibs) | ||
} | ||
|
||
function displayPage (arr, num) { | ||
for (var i = 0; i < arr.length; i++) { | ||
if (Math.floor(i / 10) === num) { | ||
arr[i].classList.remove('bangumi-hide') | ||
var img = arr[i].getElementsByTagName('img')[0] | ||
img.src = img.getAttribute('data-src') | ||
} else { | ||
arr[i].classList.add('bangumi-hide') | ||
function displayPage(arr, num) { | ||
for (let i = 0; i < arr.length; i++) { | ||
if (Math.floor(i / 10) === num) { | ||
arr[i].classList.remove('bangumi-hide') | ||
const img = arr[i].getElementsByTagName('img')[0] | ||
img.src = img.getAttribute('data-src') | ||
} else { | ||
arr[i].classList.add('bangumi-hide') | ||
} | ||
} | ||
} | ||
} | ||
|
||
for (var i = 0; i < firstpages.length; i++) { | ||
// add listener | ||
firstpages[i].onclick = firstBtn | ||
previouspages[i].onclick = previousBtn | ||
nextpages[i].onclick = nextBtn | ||
lastpages[i].onclick = lastBtn | ||
for (let i = 0; i < firstpages.length; i++) { | ||
// add listener | ||
firstpages[i].onclick = firstBtn | ||
previouspages[i].onclick = previousBtn | ||
nextpages[i].onclick = nextBtn | ||
lastpages[i].onclick = lastBtn | ||
|
||
// set page num | ||
var size = pagenums[i].parentNode.siblings().length | ||
pagenums[i].innerText = '1 / ' + (Math.ceil(size / 10) === 0 ? 1 : Math.ceil(size / 10)) | ||
firstpages[i].click() | ||
} | ||
// set page num | ||
const size = pagenums[i].parentNode.siblings().length | ||
pagenums[i].innerText = '1 / ' + (Math.ceil(size / 10) === 0 ? 1 : Math.ceil(size / 10)) | ||
firstpages[i].click() | ||
} | ||
})() |