0

I am trying to write a button with scrollTo(); but it doesn't seem to be working. Also, is there any way to get this function to work so it scrolls to an element (in my case a nav bar...) rather than pixel coordinates?

Here is my code:

<figure id="LoadVideo">
     <button type="button" onclick="ScrollDown()"> Scroll Down</button>
           <script>
                 function scrollDown(){
                      window.scrollTo(0,500);
                 }
           </script>
     <video id="LoadVid" autoplay src="images/LoadVid.mov" type="video/mov">
     </video>
   </figure>

Also if there could be any way to get animation on the button (like to come in after 7 seconds) that anybody can help with that would be awesome!

Thanks so much!

M.C.

2
  • Possible duplicate stackoverflow.com/questions/43237268/… Commented Apr 26, 2017 at 17:55
  • I recall seeing this typo before...I guess it's more common than I thought. You wrote onlick...which is not an event that a computer can capture. You probably meant onclick. Also, since JavaScript is case-sensitive, make sure you call scrollDown() and not ScrollDown(). Commented Apr 26, 2017 at 17:56

1 Answer 1

1

Well there is no lick event :) (you must mean click) so onclick and function names are case sensitive so call scrollDown and not ScrollDown

figure{height:2000px;}
<figure id="LoadVideo">
     <button type="button" onclick="scrollDown()"> Scroll Down</button>
           <script>
                 function scrollDown(){
                      window.scrollTo(0,500);
                 }
           </script>
     <video id="LoadVid" autoplay src="images/LoadVid.mov" type="video/mov">
     </video>
   </figure>

For the other question, you can get the element you want to scroll to, gets its Y offset and scroll to that, or you can use the element.scollIntoView() method.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I'd be lost without the fine people of stack!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.