That is something that involves quite a few calculations. You'll need to know the bottom of the header and the top of the footer, and from their difference remove the height of the floating sidebar. What remains is the total amount of movable distance for the floating sidebar.
From that movable difference, you would then want to position the floating sidebar along that section based on the percentage of the page that has been scrolled.
That percentage starts from when the bottom of the header is at the top of the page, and ends when the top of the footer is at the bottom of the page. In between those two extremes is the area of interest, and it's how far that the page has scrolled between those two points which determines how far to push the floating sidebar down the page.
It all gets rather complex really, but if you put your mind to it you can sort it out. We can definitely help you to answer any questions about how to do any parts that you might get stuck on.