I’m building a custom scroller for a project and i’m trying to work out how i would have the scroller handler reach the bottom of the window and for the content to also reach the bottom, ie. In this fiddle i have made: http://jsfiddle.net/BPcfc/ I use jQuery UI draggable to set the position top of the window to the same minus position of the dragged handle but when you pull the handle to the bottom of the window, there is still more content out of view. I dont even know what calculations to perform to work this out!?
The relevant JS:
$( "#dragger" ).draggable({
axis: "y",
containment: "parent",
drag: function(event, ui) {
var top = ui.offset.top;
$('#move').css('top', '-'+top+'px');
}
});
The top position of your drag handle is just one thing. You have to factor in 3 more values in your calculation:
Using these values, the calculation is quite simple:
Part 1 is needed because one windowful of your content is visible on the screen. Part 2 is needed because your handle’s top position can only range from
0towindow_height - handle_height). Simply multiply it bytopin part 3, and you’re done.I also added a little one-liner to my code which you can freely remove. It resizes your handle to give a rough idea to the user how much content they should expect.
I’ll leave the rest up to you. You would need to see IF you need a scroller at all and check your divisions for zero values.
jsFiddle Demo
Javascript:
CSS:
HTML: