scroll 1000pixels down the page on element click

2019-08-09 01:56发布

问题:

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