const dataList = [
'a',
'b',
'c',
'd',
'e',
'1',
'2',
'3',
'4',
'5'
]
function paginateArray(arr , itemPerPage , pageIndex) {
const lastIndex = itemPerPage * pageIndex;
const firstIndex = lastIndex - itemPerPage;
return arr.slice(firstIndex , lastIndex);
}
console.log(paginateArray(dataList , 5 , 2));
var host = 'https://' + document.location.hostname
var pages = [host + '/index.html', host + '/index2.html', host + '/index3.html']
var behind = document.getElementById('behind')
var forward = document.getElementById('forward')
function prev(current, pages) {
var index = pages.indexOf(current)
if (index === 0) {
return pages[pages.length - 1]
}
return pages[index - 1]
}
function next(current, pages) {
var index = pages.indexOf(current)
if (index === pages.length - 1) {
return pages[0]
}
return pages[index + 1]
}
behind.addEventListener('click', function () {
var newUrl = prev(host + window.location.pathname, pages)
window.location.href = newUrl
})
forward.addEventListener('click', function () {
var newUrl = next(host + window.location.pathname, pages)
window.location.href = newUrl
})