Scrollbar

Hi all,
Im really struggling to get my head around the logic for a scrollbar, can someone point me in the right direction of the maths for it.

Its a simple set up there is a handler, scrollbar, mask and content.

Any help would be great

Thanks