Skip to content

Instantly share code, notes, and snippets.

@Archie22is
Last active November 2, 2015 08:17
Show Gist options
  • Select an option

  • Save Archie22is/48ee0de64d21b81f30ec to your computer and use it in GitHub Desktop.

Select an option

Save Archie22is/48ee0de64d21b81f30ec to your computer and use it in GitHub Desktop.
A simple custom jQuery pagination script
<!DOCTYPE html>
<html>
<head>
<title>Prev Next In jQuery - Sibeesh Passion</title>
<script src="http://sibeeshpassion.com/content/scripts/jquery-2.0.2.min.js"></script>
<script>
$(document).ready(function () {
var $first = $(".first");
var i = 0;
$(".prev").click(function () {
++i;
if ($('#outer div').length / 2 < i) {
i = 0;
$('#outer .first').css('background', 'blue');
$first = $(".first");
} else {
$first = $first.prev();
$("#outer div").css("background", "green");
$first.css("background", "blue");
}
});
$(".next").click(function () {
++i;
if ($('#outer div').length / 2 < i) {
i = 0;
$('#outer .first').css('background', 'blue');
$first = $(".first");
} else {
$first = $first.next();
$("#outer div").css("background", "green");
$first.css("background", "blue");
}
});
});
</script>
<style>
#outer div {
width: 20px;
height: 20px;
border: 1px solid #ccc;
border-radius: 5px;
padding: 10px;
margin: 10px;
box-shadow: 1px 1px 1px #999;
font-style: oblique;
text-align: center;
float: left;
background: green;
}
#outer .first {
background: blue;
}
.prev, .next {
font-weight: bold;
font-size:30px;
padding:10px;
cursor:pointer;
}
#container {
text-align: center;
width: 50%;
margin-left: 25%;
}
</style>
</head>
<body>
<div id="container">
<div id="outer">
<div>-6</div>
<div>-5</div>
<div>-4</div>
<div>-3</div>
<div>-2</div>
<div>-1</div>
<div class="first">0</div>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
</div>
<div>
<table>
<tr>
<td class="prev"
title="Previous"><<<</td>
<td class="next"
title="Next">>>></td>
</tr>
</table>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment