今天接到通知说要搞个聊天室,这个东西网上多的不得了,随便一搜到处都是,但是要一个真正适合自己的恐怕还要自己动手了。在用JavaScript调节滚动条自动向下滚动的时候,发现了几个方法,特此记在这里:
首先是doScrooll方法,可以指定滚动的方向。但是不能一下子滚动到最极端。
object .doScroll( [ sScrollAction ] )
sScrollAction
Optional.
A String that specifies how the object scrolls, using one of the following values.
-
scrollbarDown
- Default. Down scroll arrow is at the specified location.
- Horizontal scroll thumb or box is at the specified location.
- Left scroll arrow is at the specified location.
- Page-down scroll bar shaft is at the specified location.
- Page-left scroll bar shaft is at the specified location.
- Page-right scroll bar shaft is at the specified location.
- Page-up scroll bar shaft is at the specified location.
- Right scroll arrow is at the specified location.
- Up scroll arrow is at the specified location.
- Vertical scroll thumb or box is at the specified location.
scrollbarHThumb
scrollbarLeft
scrollbarPageDown
scrollbarPageLeft
scrollbarPageRight
scrollbarPageUp
scrollbarRight
scrollbarUp
scrollbarVThumb
如果想一下子滚到最下面可以用下面的代码(IE和Firefox都可以用):
f(divContent.scrollHeight>divContent.offsetHeight)
divContent.scrollTop=divContent.scrollHeight-divContent.offsetHeight;
注:divContent是一个带滚动条的div。