简体   繁体   English

当 javascript int++ 达到选定值时,如何跳转到 Page Top []?

[英]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.

相关问题 我如何获得一个滚动页面和导航的导航,当它使用普通的javascript到达顶部导航 - how do i get a navigation that scrolls with page and stick when it reaches the top nav with plain javascript 当锚点到达视口顶部时,如何触发jQuery? - How do I trigger jQuery when an anchor reaches the top of the viewport? 当时间达到 5 分钟到最晚时,JavaScript 重定向到另一个页面 - JavaScript redirect to another page when time reaches 5 minutes to top of hour javascript:当 window 到达顶部时 - javascript: when window reaches the top 当滚动到达div的顶部时如何打印scrolltop()值0 - How can I print scrolltop() value 0 when scroll reaches top of the div Django、Ajax 和 JS。 提交评论时如何防止页面重新加载并跳转到页面顶部 - Django, Ajax and JS . How to prevent page reloads and jump ups to the top of the page when i submit a comment 如何使用 vanilla javascript 判断元素的顶部或底部何时滚动到页面顶部 - How do I tell when the top or bottom of an element scrolls to the top of the page using vanilla javascript 当导航栏到达页面顶部时,我的粘性标头会导致随后的div跳到100像素左右,无法找出解决方法吗? - My sticky header causes the subsequent div to jump about 100 pixels when the navbar reaches the top of the page, can't figure out a fix? 当用户到达页面末尾以加载新内容时,如何调用JavaScript(AJAX)函数? - How do you call a JavaScript (AJAX) function when the user reaches the end of a page to load new content? 当元素到达页面顶部时修复元素 - Fixing an element when it reaches the top of the page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM