Forum Discussion
Scroll Bar start position
That's really cool - thanks. So how could you scroll, say, to the middle?
Chris
- RussellKillips-6 years agoCommunity Member
Try dividing the scrollHeight by 2 to get to the middle.
var x = document.getElementsByClassName("scrollarea-area");
x[0].scrollTop = x[0].scrollHeight/2;- KristinaMarinch5 years agoCommunity Member
Russel, you saved me with this code. Thank you very much!
- RussellKillips-6 years agoCommunity Member
I forgot to account for the offset.
To get to the bottom, use:
var x = document.getElementsByClassName("scrollarea-area")[0];
x.scrollTop = x.scrollHeight-x.offsetHeight;And to get to the Middle use:
var x = document.getElementsByClassName("scrollarea-area")[0];
x.scrollTop = (x.scrollHeight-x.offsetHeight)/2;- TeoKar5 years agoCommunity Member
Hello Russel, thank you for the effort putting in examplaining javascript to us, noobs :)
I was wondering. Will this be possible if the slider was placed horizontally instead of vertically ?
var x = document.getElementsByClassName("scrollarea-area");
x[0].scrollTop = 0;
var width_Slider1 = x[0].scrollWidth - x[0].offsetWidth;x[0].onscroll = function(){
var player = GetPlayer();
player.SetVar("width_Slider1",x[0].scrollTop);
}; - ATusenius4 years agoCommunity Member
Thanks a lot for the JavaScript Code! Is there a way to make the scroll jump to 2/3 or 3/4th?
- RussellKillips-4 years agoCommunity Member
Hello Antje
For 2/3 use:
var x = document.getElementsByClassName("scrollarea-area")[0];
x.scrollTop = (x.scrollHeight-x.offsetHeight) * 2/3;For 3/4 use:
var x = document.getElementsByClassName("scrollarea-area")[0];
x.scrollTop = (x.scrollHeight-x.offsetHeight) * 3/4;