2
How to page a text with Jquery ? I have a large text of about 5000 characters and I need to make it stay in some 5 pages with option NEXT PAGE AND PREVIOUS PAGE, I searched and I can not find any tutorial on the subject, only plugins that do this, someone can help me ?
I started the script but my weak programming logic did not let me continue... Follow what I have:
<script>
$(document).ready(function() {
var pagina = 1;
var texto2 = $("#none").val().toString();
var len = texto2.length;
if (len > 800 || len < 1600)
{
var len = texto2.slice(0, 800);
var len2 = texto2.slice(800, 1600);
var len3 = texto2.slice(1600, 2400);
var len4 = texto2.slice(2400, 3000);
}
var paginatotal = 1;
$("#divtest").append(len);
});
$("#divtest2").click(function() {
if (pagina <= paginatotal)
{
var pagina = pagina + 1;
}
else
{
var pagina = paginatotal;
}
});
$("#divtest3").click(function() {
if (pagina > 1)
{
var pagina = pagina - 1;
}
else
{
var pagina = 1;
}
});
</script>
<textarea id="none" style="display: none;"><?php echo $row[texto]; ?></textarea>
<hr><div id="divtest"></div>
<BR><div id="divtest2">proxima</div><div id="divtest3">anterior</div>
Probably to continue I need to create a loop for instead of the IF with the Slices...but I locked...
Sergio, you quoted Slice very well. I’m just a little against making this control of the division of words in the JS because it worsens the performance of the user, I mean, in speed, because the DOM would have to be changed with each pagination. If the words already come cut right on the server, just show and hide the correct Ivs. What do you think?
– rafaels88
@rafaels88, agree. I put the solution only with JS/jQuery because the question is not tagged
php
– Sergio
It’s true. I only realized that PHP was there because of the code.
– rafaels88
Valew @Sergio!!! was very confused my code, I was able to adapt your code to what I needed!!!
– Alan PS