Use anchors to locate page locations

Similar to the chat page, the new message will be displayed at the bottom of the page, but by default only the data is loaded, and the page position is still the current position.

In order to display the data in the visible area in real time, you can add a blank label (add ID) under the label of the chat record display page by dynamically positioning the label.

The following code:

<div id="chatDiv">
    <div class="chat">聊天内容1</div>
    <div class="chat">聊天内容2</div>
    <div class="chat">聊天内容3</div>
</div>
<div id="bottomDiv" style="width:10px;height:10px"></div>

The above code defines the anchor: <div id="bottomDiv" style="width:10px;height:10px"></div>

After confident that the chat content is generated, locate it through js code

The following code:

// Business code 

document.getElementById( 'bottomDiv').scrollIntoView();

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325348492&siteId=291194637