scroll 1000pixels down the page on element click

依然范特西╮ 提交于 2019-12-11 05:53:43

问题


I have div id="menuitem1" and, when someone clicks on that div, I want the page to scroll 1000px down the page.

I know this is something that's easy to Google, but for some reason, even after reading articles and trying all sorts of things, I can't figure it out. I'm new to this stuff, so please be understanding of that. Thanks!

<script type="text/javascript">
$("#menuitem1").click(function(){
$(window).scrollTo( {top:'1000px'}, 800 );
});
</script>

回答1:


the javascript function you need would look something link this:

function pageScroll() {
        window.scrollBy(0,1000); // horizontal and vertical scroll increments
}

and for the html button, well, just:

<input type="button" onClick="pageScroll()" value="Scroll Page">

best of luck



来源:https://stackoverflow.com/questions/14299910/scroll-1000pixels-down-the-page-on-element-click

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!