Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Advanced Node.js Development

You're reading from   Advanced Node.js Development Master Node.js by building real-world applications

Arrow left icon
Product type Paperback
Published in Mar 2018
Publisher Packt
ISBN-13 9781788393935
Length 592 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Andrew Mead Andrew Mead
Author Profile Icon Andrew Mead
Andrew Mead
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Getting Set Up FREE CHAPTER 2. MongoDB, Mongoose, and REST APIs – Part 1 3. MongoDB, Mongoose, and REST APIs – Part 2 4. MongoDB, Mongoose, and REST APIs – Part 3 5. Real-Time Web Apps with Socket.io 6. Generating newMessage and newLocationMessage 7. Styling Our Chat Page as a Web App 8. The Join Page and Passing Room Data 9. ES7 classes 10. Async/Await Project Setup 11. Other Books You May Enjoy

Autoscrolling


If we're going to build a frontend we might as well do it right. In this section, we're going to add an autoscrolling feature. So if a new message comes in, it is visible inside of the messages panel. Now right away this is not a problem. I type an a, I hit enter, and it shows up. However, as we get further down the list, you'll see the messages start to disappear down the bottom of the bar:

Now I can indeed scroll down to see the most recent messages, but it would be nice if I'm automatically scrolled to the most recent message. So if a new message comes in like 123, I'm automatically brought to the bottom.

Now, obviously, if someone does scroll up to read an old message, we're going to want to keep them there; we're not going to want to scroll them to the bottom, that would be just as annoying as not being able to see the new messages in the first place. This means that we're going to go ahead and calculate a threshold. If someone can see that last message, we're going to go...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image