It should be a div that use javascript to set a timer to adjust the x-y position accordingly.
Because not all browsers support div, some browsers use the layer tag.
Just think of the layer/div as a place holder, and you can use css to style it (border, bgcolor, background-image, font size...etc.). The properties (style, size, position...etc.) won't change by itself. So we need to use javascript to make it dynamic. It can be event driven (onclick, onmouseover...etc.), or we can set a timer so every 0.1 seconds, it will run some javascripts.
In your case, I think a common way to do it is to set a timer to check the layer/div position and make sure it is always, for example, 20px away from the right of the browser screen, and 200px away from the top. The timer can be set to every 0.1 second, so it is fast enough that when the user scroll, the menu follows.
And it is always on the top because after we set the css style to use absolute position, then it is on the top of the other regular elements. And if you have more "layers" that are set to absolute position, then I think it is the 'z-index' property that determines which one is above and which is below.
Please correct me if I was wrong. Hope that answers your question.