没有数据库的PHP分页?

时间:2017-06-11 17:01:46

标签: php pagination

我想在没有使用PHP的数据库的情况下创建一个简单的分页。是否有可能在没有数据库的情况下对我目前所拥有的内容进行分页?如果是这样,有人可以指向教程或什么?

https://codepen.io/anon/pen/vZGerv

HTML

 <div> 1 </div>
 <div> 2 </div>
 <div> 3 </div>
 <div> 4 </div>
 <div> 5 </div>
 <div> 6 </div>
 <div> 7 </div>
 <div> 8 </div>
 <div> 9 </div>
 <div> 10</div>
 <div> 11</div>
 <div> 12</div>
 <a href="#" id="loadMore">Next Page</a>

CSS

body {
background-color: #f6f6f6;
width: 400px;
margin: 60px auto;
margin-top: 5px;
font: normal 13px/100% sans-serif;
color: #444;
}
div {
display:none;
padding: 10px;
border-width: 0 1px 1px 0;
border-style: solid;
border-color: #fff;
box-shadow: 0 1px 1px #ccc;
margin-bottom: 5px;
background-color: #f1f1f1;
}
.totop {
position: fixed;
bottom: 10px;
right: 20px;
}
.totop a {
display: none;
}
a, a:visited {
color: #33739E;
text-decoration: none;
display: block;
margin: 10px 0;
}
a:hover {
text-decoration: none;
}
#loadMore {
padding: 10px;
text-align: center;
background-color: #33739E;
color: #fff;
border-width: 0 1px 1px 0;
border-style: solid;
border-color: #fff;
box-shadow: 0 1px 1px #ccc;
}
#loadMore:hover {
background-color: #fff;
color: #33739E;
}

JS

(function() {
var divElements = [].slice.call(document.querySelectorAll("div"));
var loadMore = document.querySelector('#loadMore');
var divNumber = 2;

loadMore.addEventListener('click', function(e) {
    e.preventDefault();
    for (var i = 0; i < divNumber; i++) {
    window.scrollTo(0,document.body.scrollHeight);
        if (i < divElements.length) {
            divElements[i].style.display = 'block';
        }

        if (i >= divElements.length) {
            loadMore.innerHTML = "Load Completed";
            return;
        }

    }
    divElements.splice(0, divNumber);

});
})();
loadMore.click();

0 个答案:

没有答案