Home > Web Front-end > JS Tutorial > How to implement the principle of iframe upper and lower scroll bars at the bottom by default_Basic knowledge

How to implement the principle of iframe upper and lower scroll bars at the bottom by default_Basic knowledge

WBOY
Release: 2016-05-16 17:47:05
Original
933 people have browsed it
Question: How do I frame the upper and lower scroll bars to be at the bottom by default? It is a chat tool with a lot of data. The up and down scroll bars that appear every time it is refreshed are at the top by default. You still need to scroll down to the bottom to see the chat history. There is Is there a way to make it appear below?
Answer: Write window.scrollTo(0,9999999) directly in the iframe or set the scrollTop of the container such as div
Copy code The code is as follows:

document.getElementById(“x”).scrollTop = document.getElementById(“x”).scrollHeight
window.scrollTo(0 ,9999999)

This is solved below, but after there is new information, the scroll bar will not automatically go to the bottom. I hope that like the QQ chat window, when there is new content, it will automatically go to the bottom. Below, how should we solve it?

Then you should determine the position of the currently generated content, that is, its top or margin-top, and then set the height of the scroll bar. This is enough. Call the scroll bar every time it is generated. The height changes. Every time you get new data, call the window.scrollTo(0,9999999) method to solve this problem!
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template