Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
858 views
in Technique[技术] by (71.8m points)

How do i paginate long articles from the client side using javascript or jquery

I am trying to come up with a way to paginate an article smoothly from the client side using Jquery or Javascript so that long articles can be viewed as multiple pages.

I need it to split the content based on page size and even break sentences and divs into different pages(if need be).

I need it to be able to handle iframes, images, list items, tables and videos as well

I really hope someone can help me soon, as i have been trying for months to try to fix this situation.

If anyone needs more clarification, please do ask

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You will need to do that using Ajax.

A very simplified way of doing this would be:

HTML:

<div id="container"></div>
<button id="loadmore">Load More!</button>

jQuery / Ajax:

var i = 1;
$("#loadmore").click(function(){ // on load more button click
    $.ajax({
        url: "datagrab.php", // get data from backend
        method: "post",
        data: {section: i} // which section to grab data from (ie: 1 = the first 200 characters; 2 = from the 200th character to the 400th e.t.c...)
        success: function(data){
            $("#container").append(data); // append data to #container
            i++;
        }, 
        error: function(){
            alert("There was a problem!");
        }
    });
});

Obviously, this is a very basic approach to it, however, based on the "information" you gave me, this is all I can really provide..

If you want to find out more about how to do this, have a look at some YouTube videos about pagination with Ajax.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...