Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
54
rated 0 times [  57] [ 3]  / answers: 1 / hits: 15306  / 5 Years ago, mon, march 11, 2019, 12:00:00

enter



I wanna listen to scroll event on a specific element, so that there will be an arrow icon indicating more messages below after the user scrolled up the messages box. Exactly like the Youtube live chat image above.



Or is there an another way doing this?


More From » javascript

 Answers
25

You can listen for a scroll event on any element using the following code:



element.addEventListener(scroll, function(){
// do stuff
});


You can then get the current scroll position of that element by using element.scrollTop



From here, you can check to see if the element's scroll position is less than its total height. If it is, display your button to scroll back down. On click of the button with the down arrow, you simply use element.scrollTo() which even has built in easing effects in modern browsers. Just pass the scroll value as the height of the containing element.


[#52443] Wednesday, March 6, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
josiah

Total Points: 208
Total Questions: 105
Total Answers: 107

Location: Seychelles
Member since Mon, Jun 28, 2021
3 Years ago
;