javascript - 反应滚动到顶部不起作用?需要新的解决方案
问题描述
因此,当用户提交表单时,我试图滚动到屏幕顶部。堆叠溢出的答案似乎对我不起作用。
这是我的代码:
handleClick (evt) {
evt.preventDefault();
this.calculateScore();
this.setState({submittingQuiz: true});
// let myPage = document.querySelector('body');
// myPage.scrollTo(0,0); Couldn't get this way to work either
window.scrollTo({top: 0, behavior: 'smooth'})
}
有关如何解决此问题的任何想法。我有一些样式,我认为可能会弄乱它..
html {
background-image: url('./tupac.jpeg');
background-position-y: -580px;
background-repeat: no-repeat;
background-size: cover;
overflow: hidden;
}
Anyone got a clue?
解决方案
这可能是因为应用程序的body
一个height: 100vh;
或一些主容器具有相同的height: 100vh;
尝试删除应用程序height: 100vh;
的body
主容器并再次测试。
推荐阅读
- c++ - 在骰子上没有得到正确的预期输出
- python - 我基本上想做一个元素加法,但只使用 for 循环,所以没有 numpy 或 map
- java - 怎么办这个错误 - androidx.appcompat.widget.AppCompatSeekBar 不能转换为 android.view.ViewGroup?
- javascript - 如何在子字符串后修改jquery中的css值?
- scikit-learn - 无法使用 sklearn 中的稀疏矩阵计算 silhouette_score
- connectycube - 未捕获的 DOMException:此轨道已设置在发件人上。连接立方体.min.js:1
- java - NavigationDrawer 阻止/停止活动上的其他按钮
- react-native - android studio错误-无法确定任务':app:installDebug'的依赖关系
- jquery - 在特定索引处插入新元素 - 同位素 Jquery
- python - 将一个节点链替换为graphdb中的另一个节点链?像字符串替换