I'm getting this error in Chrome only (it works in Safari/Firefox):Failed to execute 'scroll' on 'Window': No function was found that matched the signature provided.
The code is inside an inline event:
<div onclick='function scrollToByIntoView () {
window.scroll({
top: 0,
left: 0,
behavior: "smooth"
})
};
scrollToByIntoView();'>
I can't understand what's the problem.
PS: Note that this code is the output I get after DOM rendering. The actual code is splitter in different components/functions that I use in my server side templating engine, as, as noted in comments below, mixing this code directly should be avoided.
Definition and Usage The scrollTo() method scrolls the document to specified coordinates.
To scroll the page with JavaScript, its DOM must be fully built. For instance, if we try to scroll the page with a script in <head> , it won't work. Regular elements can be scrolled by changing scrollTop/scrollLeft . We can do the same for the page using document.
If you look to the right side of your keyboard, you'll see four arrows: up, down, left, and right. You can use the down arrow to scroll down on a web page and the up arrow to scroll back up.
Perhaps try scrollTo. This is cross browser supported for x and y coordinates.
http://www.w3schools.com/jsref/met_win_scrollto.asp
<div onclick="window.scrollTo(0,0)">...</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With