-1

can someone help, i am currently using javascript to show a hidden div when a check box is checked and i also want it to scroll the page down automatically after the div is showing as to bring the div into focus, at the moment it is not doing anything and i want it to scroll down by a certain percentage like 5% or something to bring the div into focus on the page, can someone pelase show me how to do this ?

javascript:

    <script>
      function showMore(more) {
          document.getElementById("content3").style.display = more.checked ? "block" : "none";
document.body.scrollBottom = document.documentElement.scrollBottom = 10%;
      }
    </script>

html:

<input type="checkbox" id="tick2" class="tick2" name="tick2" value="0" onClick="showMore(this);" />
John Taylor
  • 1,467
  • 2
  • 11
  • 15
  • I'm pretty sure you don't want two `=` signs on the third line. – Grim... Apr 01 '14 at 12:41
  • check [here](http://stackoverflow.com/questions/11715646/scroll-automatically-to-the-bottom-of-the-page) – Wundwin Born Apr 01 '14 at 12:44
  • possible duplicate of [Scroll automatically to the bottom of the page](http://stackoverflow.com/questions/11715646/scroll-automatically-to-the-bottom-of-the-page) – morten.c Apr 01 '14 at 12:44

1 Answers1

1

Use window.scrollTo(0,document.body.scrollHeight); to scroll to the bottom of a page.

If you want to scroll to the bottom 10%, you need to take the screen height away from the page height.

window.scrollTo(0,((document.body.scrollHeight - window.innerHeight) / 100) * 90); should do it, where '90' is the percentage of the page you want to scroll down to.

Grim...
  • 16,518
  • 7
  • 45
  • 61