2014-04-01 39 views
-1

有人可以帮助,我目前使用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:

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

我很确定你不想在第三行有两个'='符号。 –

+0

check [here](http://stackoverflow.com/questions/11715646/scroll-automatically-to-the-bottom-of-the-page) –

+0

[自动滚动到页面底部](http ://stackoverflow.com/questions/11715646/scroll-automatically-to-the-bottom-of-the-page) –

回答

1

使用window.scrollTo(0,document.body.scrollHeight);滚动到页面底部。

如果您想滚动到底部的10%,则需要使屏幕高度远离页面高度。

window.scrollTo(0,((document.body.scrollHeight - window.innerHeight)/100) * 90);应该这样做,其中'90'是您要向下滚动到的页面的百分比。