For performance, I am not creating many .HTML files. Instead of it I am creating the page content into a div so it will be show like below
<div id="page1"> first page content</div>
<div id="page2"> first page content</div>
<div id="page3"> first page content</div>
<div id="page4"> first page content</div>
But the problem is, the second page automatically scroll, when I scroll the first page even the second page is hidden.
<button style="position:fixed" onclick="page1.style.display='none';page2.style.display='';">Show page 2</button>
<button style="position:fixed;margin-left:100px" onclick="page1.style.display='';page2.style.display='none';">Show page 1</button>
<div id="page1">
<div>PAGE 1 - 1</div><div>PAGE 1 - 2</div><div>PAGE 1 - 3</div><div>PAGE 1 - 4</div><div>PAGE 1 - 5</div><div>PAGE 1 - 6</div><div>PAGE 1 - 7</div><div>PAGE 1 - 8</div><div>PAGE 1 - 9</div><div>PAGE 1 - 10</div><div>PAGE 1 - 11</div><div>PAGE 1 - 12</div><div>PAGE 1 - 13</div><div>PAGE 1 - 14</div><div>PAGE 1 - 15</div><div>PAGE 1 - 16</div><div>PAGE 1 - 17</div><div>PAGE 1 - 18</div><div>PAGE 1 - 19</div><div>PAGE 1 - 20</div><div>PAGE 1 - 21</div><div>PAGE 1 - 22</div><div>PAGE 1 - 23</div><div>PAGE 1 - 24</div><div>PAGE 1 - 25</div><div>PAGE 1 - 26</div><div>PAGE 1 - 27</div><div>PAGE 1 - 28</div><div>PAGE 1 - 29</div><div>PAGE 1 - 30</div><div>PAGE 1 - 31</div><div>PAGE 1 - 32</div><div>PAGE 1 - 33</div><div>PAGE 1 - 34</div><div>PAGE 1 - 35</div><div>PAGE 1 - 36</div><div>PAGE 1 - 37</div><div>PAGE 1 - 38</div><div>PAGE 1 - 39</div><div>PAGE 1 - 40</div><div>PAGE 1 - 41</div><div>PAGE 1 - 42</div><div>PAGE 1 - 43</div><div>PAGE 1 - 44</div><div>PAGE 1 - 45</div><div>PAGE 1 - 46</div><div>PAGE 1 - 47</div><div>PAGE 1 - 48</div><div>PAGE 1 - 49</div><div>PAGE 1 - 50</div><div>PAGE 1 - 51</div>
</div>
<div id="page2" style="display:none">
<div>PAGE 2 - 1</div><div>PAGE 2 - 2</div><div>PAGE 2 - 3</div><div>PAGE 2 - 4</div><div>PAGE 2 - 5</div><div>PAGE 2 - 6</div><div>PAGE 2 - 7</div><div>PAGE 2 - 8</div><div>PAGE 2 - 9</div><div>PAGE 2 - 10</div><div>PAGE 2 - 11</div><div>PAGE 2 - 12</div><div>PAGE 2 - 13</div><div>PAGE 2 - 14</div><div>PAGE 2 - 15</div><div>PAGE 2 - 16</div><div>PAGE 2 - 17</div><div>PAGE 2 - 18</div><div>PAGE 2 - 19</div><div>PAGE 2 - 20</div><div>PAGE 2 - 21</div><div>PAGE 2 - 22</div><div>PAGE 2 - 23</div><div>PAGE 2 - 24</div><div>PAGE 2 - 25</div><div>PAGE 2 - 26</div><div>PAGE 2 - 27</div><div>PAGE 2 - 28</div><div>PAGE 2 - 29</div><div>PAGE 2 - 30</div><div>PAGE 2 - 31</div><div>PAGE 2 - 32</div><div>PAGE 2 - 33</div><div>PAGE 2 - 34</div><div>PAGE 2 - 35</div><div>PAGE 2 - 36</div><div>PAGE 2 - 37</div><div>PAGE 2 - 38</div><div>PAGE 2 - 39</div><div>PAGE 2 - 40</div><div>PAGE 2 - 41</div><div>PAGE 2 - 42</div><div>PAGE 2 - 43</div><div>PAGE 2 - 44</div><div>PAGE 2 - 45</div><div>PAGE 2 - 46</div><div>PAGE 2 - 47</div><div>PAGE 2 - 48</div><div>PAGE 2 - 49</div><div>PAGE 2 - 50</div><div>PAGE 2 - 51</div>
</div>
The sample in codepen
https://codepen.io/merbin2012/pen/qBMdVKZ?editors=1000
I know the solution, we can save the final scrolling point and we can scroll when come to the first page and we can use scrolltotop, but it is very difficult to manage, because I have more than 30pages.
2
Answers
One possible approach:
1
(occupy available space)overflow: auto
"is-active"
set itsscrollTop
to0
Another approach using your HTML sample is to address your comment in your original post:
A straightforward solution is to: assign a page number attribute to each page element (i.e. your generated HTML content page); add an entry to a
key/value
object; assign thekey
to the page number attribute value; assignvalue
to thescrollTop
position retrieved just before another page element is displayed.