I have a container that have multiple a4 page (number is random) and I want to detect what page I'm currently viewing.
This is my code:
<div class="mycont">
<div id="page1" style="width: 21cm; height:29.7cm; border: 1px solid; margin: 10px 0">
<h1>page1</h1>
</div>
<div id="page2" style="width: 21cm; height:29.7cm; border: 1px solid; margin: 10px 0">
<h1>page2</h1>
</div>
<div id="page3" style="width: 21cm; height:29.7cm; border: 1px solid; margin: 10px 0">
<h1>page3</h1>
</div>
</div>
<div style="position: fixed; bottom: 0; left: 50%; padding: 10px 50px; background-color: #ccc;" id="curpage">cur page 1</div>
And with this script I can detect only 1 page
<script>
$(document).ready(function() {
var target = $("#page2").offset().top;
var interval = setInterval(function() {
if ($(window).scrollTop() >= target) {
$("#curpage").text("cur page 2");
}
}, 250);
});
</script>
How to detect page 3,4... 50,51 etc ?