简体   繁体   English

检查时的javascript滚动到页面底部

[英]javascript on check scroll to bottom of page

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 在复选框被选中时显示隐藏的 div,我还希望它在显示 div 后自动向下滚动页面以使 div 成为焦点,目前它不是做任何事情,我希望它向下滚动一定的百分比,比如 5% 或其他东西以使 div 聚焦在页面上,有人可以告诉我如何做到这一点吗?

javascript: javascript:

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

html: html:

<input type="checkbox" id="tick2" class="tick2" name="tick2" value="0" onClick="showMore(this);" />

Use window.scrollTo(0,document.body.scrollHeight);使用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.如果要滚动到底部 10%,则需要将屏幕高度远离页面高度。

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.应该这样做,其中“90”是您要向下滚动到的页面的百分比。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM