如何将页面滚动到顶部 [英] How do I make a page scroll to the top

查看:143
本文介绍了如何将页面滚动到顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个< div>在我的应用程序中标记我在屏幕上最小化,从而只显示该部门内容的顶行。


用户使用鼠标悬停事件激活内容(最大化内容)。


激活后,用户可以向下滚动内容,鼠标输出再次最小化。


我的问题是这样 - 当内容最小化时只显示一行,它就是用户滚动到的位置。


我想将页面备份移到顶部作为我的最小化过程的一部分。编写代码的好方法是什么?


这是我最小化的方法:

I have a <div> tag in my app that I minimize on the screen thereby only showing the top line of the content in that division.

The user activates the content (maximizes the content) with the mouseover event.

When active the user can scroll down through the content and mouseout minimizes it again.

My problem is this - when the content is minimized to reveal only one line, it is at the point where the user had scrolled to.

I would like to move the page backup to the top as part of my minimizing procedure. What is a good way to script that code?

Here is my method for minimizing:

展开 | 选择 | Wrap | 行号

推荐答案

我假设你的意思是div中的页面。使用 scrollTop 属性。
I assume you mean the page within the div. Use the scrollTop property.

是的,你是对的。你的建议是有效的,除非我使用mouseout最小化或由于其他原因我还没有弄清楚,我只能使用右侧的滚动条向下滚动。一旦我将光标移动到屏幕的中心,它就会自动将内容滚动回到顶部(不关闭窗口,只是滚动顶部)。为什么会这样?
Yes you are correct. And your suggestion works, except since I am using mouseout to minimize or for some other reason I have not been able to figure out yet, I can only scroll down using the scroll bar on the right side. As soon as I move the cursor into the center of the screen, it automatically scrolls the content back to the top (not closing the window, just scrollTop). Why would that be?


您是否尝试使用display:none来隐藏折叠的div?


如果这个div是负责制作页面滚动,设置此样式会使页面内容再次变小...从而将页面滚动回原来的位置。




我使用以下代码对此进行了测试,并且工作正常:

Have you tried using display:none to hide the collapsed div?

I would have thought that if this div is responsible from making the page scroll, that setting this style would make the page content smaller again...thereby scrolling the page back up to where it would have been before.

[edit]
I tested this with the following code and it works fine:

< span class =codeLinkonclick =Blur(this,this.parentNode.parentNode,getChildren(this),true);>展开 | 选择 | Wrap | 行号


这篇关于如何将页面滚动到顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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