MCPcopy Create free account
hub / github.com/codemistic/Web-Development / autoscroll

Function autoscroll

Chat_app/public/js/chat.js:19–35  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17const { username, room } = Qs.parse(location.search, { ignoreQueryPrefix: true })
18
19const autoscroll = () => {
20 // New message element
21 const $newMessage = $messages.lastElementChild
22 // Height of the new message
23 const newMessageStyles = getComputedStyle($newMessage)
24 const newMessageMargin = parseInt(newMessageStyles.marginBottom)
25 const newMessageHeight = $newMessage.offsetHeight + newMessageMargin
26 // Visible height
27 const visibleHeight = $messages.offsetHeight
28 // Height of messages container
29 const containerHeight = $messages.scrollHeight
30 // How far have I scrolled?
31 const scrollOffset = $messages.scrollTop + visibleHeight
32 if (containerHeight - newMessageHeight <= scrollOffset) {
33 $messages.scrollTop = $messages.scrollHeight
34 }
35}
36
37//getting data from server in text form
38socket.on('message', (message) => {

Callers 1

chat.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected