[英]How do I jump to the Page Top [ ] when a javascript int++ reaches a chosen value?
As the header says, how do I jump to the Page Top ['div id ="Top" /div'] when a javascript int++ reaches a chosen value?正如标题所说,当 javascript int++ 达到选定值时,如何跳转到 Page Top ['div id ="Top" /div'] ? I am not looking to click a button to do so.
我不想点击按钮来这样做。 My need arises out of showing visual background slideshow content before making the text div show using 'visibility:visible;'.
在使用“visibility:visible;”显示文本 div 之前,我需要显示视觉背景幻灯片内容。 That is not an issue.
那不是问题。 What is an issue is doodling with the mouse and moving the presently 'visibility:hidden;'
问题是用鼠标涂鸦并移动当前的“可见性:隐藏;” text down the page looking for it and fiddling about and moving away unknowingly from the top introductory text to come.
沿着页面向下寻找文本并摆弄并在不知不觉中从顶部的介绍性文本中移开。 So, following my javascript line of 'document.getElementById("ArticleStyle").style.visibility = "visible";'
因此,按照我的 javascript 行 'document.getElementById("ArticleStyle").style.visibility = "visible";' I would wish to add a line to command the page to focus/navigate back to the top so it will be forced to start at 'div id="Top" /div' when the text is set to become visible.
我希望添加一行来命令页面聚焦/导航回顶部,这样当文本设置为可见时,它将被迫从 'div id="Top" /div' 开始。
try this:尝试这个:
<button onclick="goToTop()"></button>
function goToTop() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
Alternatively you could also scroll the element into view.或者,您也可以将元素滚动到视图中。
var elmnt = document.getElementById("top");
elmnt.scrollIntoView();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.