scrollTo()函数什么都不做 [英] scrollTo() function does nothing

查看:111
本文介绍了scrollTo()函数什么都不做的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用香草JS滚动到页面底部,但是遇到了问题.下面的代码应该滚动到页面底部:

I wanted to scroll to the bottom of the page using vanilla JS, but I encountered a problem. The code below is supposed to scroll to the bottom of the page:

window.scrollTo(0,document.body.scrollHeight);

它所做的只是在控制台中记录未定义".输入

Whereas all it does is logs "undefined" in the console. Inputting

document.body.scrollHeight

返回一个整数736.除此之外,我输入该函数的参数无关紧要,什么也没发生.而且,它仅在一个网站上发生.可能很重要(不确定)是该网站隐藏了其垂直滚动条,甚至认为该网站的内容列表很长.

returns an integer 736. Other than that, it doesn't matter what I input into the function's parameters, nothing happens. What more, it only happens on one website. What may matter (not sure) is that the website hides its vertical scrolling bar, even thought it has a really long list of content.

推荐答案

如果您尝试像var a = 5一样在浏览器的控制台中键入内容,则也会得到未定义的内容.碰巧您的示例和我的示例未返回任何内容.

If you will try to type in browser's console like a var a = 5 you also will get undefined. It happens that your example and my did not return anything.

这篇关于scrollTo()函数什么都不做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆