Forum Discussion
Scroll Bar start position
For the not-so javascript minded ones... in Russel's code he uses
var x = document.getElementsByClassName("scrollarea-area")[2];
document.getElementsByClassName captures all HTML-elements on the page with the given class-name. So if you have 5 scrollareas they all get into a HTMLCollection. Given that it a possibility is you capture all scrollAreas and then can act upon that... something like...var scrollAreaCollection = document.getElementsByClassName("scrollarea-area");
So this scrollAreaCollection now is a HTMLCollection of all scrollareas on your page... and as Russel does too, you can either loop them all...//loop through the collection
for(var i = 0; i < scrollAreaCollection.length; i++){
scrollAreaCollection[i].scrollTop = scrollAreaCollection[i].scrollHeight-scrollAreaCollection[i].offsetHeight;
}
or act on a specific one...like this...
var scrollAreaToChange = scrollAreaCollection[0];
scrollAreaToChange.scrollTop = scrollAreaToChange.scrollHeight-scrollAreaToChange.offsetHeight;
Related Content
- 6 months ago
- 6 months ago