Your analysis is spot on (and I must say, those diagrams are quite impressive!)
However, in regards to your previous post, there seems to be an excess of information provided.
The key concept to grasp here is the relationship between the document and viewport. The document remains fixed while the viewport moves along with you, having a scroll offset.
In theory, you have the option to position your dialog window relative to either of these elements. Let's imagine the dialog as a simple division element:
<body>
<button id="save">Save</button>
<div id="dialog" style="position:absolute;">Are you sure?</div>
</body>
If you wish to position that element in relation to your button when clicked, you could utilize the document:
<script>
document.getElementById("save").onclick = function(e) {
var dialog = document.getElementById("dialog");
dialog.style.top = e.pageY + "px";
/*
The pageY value indicates the mouse position relative to the
document at the time of this event.
*/
};
</script>
Alternatively, you could opt for utilizing the viewport:
<script>
document.getElementById("save").onclick = function(e) {
var dialog = document.getElementById("dialog");
dialog.style.top = e.clientY + window.pageYOffset + "px";
/*
Here, clientY provides the mouse position relative to
the viewport during this event, while pageYOffset
represents the user's scroll distance.
*/
};
</script>
Another approach would involve using the button itself. This method ensures a consistent position regardless of where exactly the user clicks:
<script>
document.getElementById("save").onclick = function(e) {
var dialog = document.getElementById("dialog");
dialog.style.top = document.getElementById("save").offsetTop + "px";
/*
Utilizing offsetTop gives the button's position relative to its nearest
positioned ancestor. For deeply nested elements, additional calculations may be required.
(jQuery's "offset" method handles this automatically).
*/
};
</script>
For applying the last method with jQuery's dialog class, you can simply follow this procedure:
<script>
$("#save").click(function(e) {
$("#dialog").dialog({
position: {
my: "top",
at: "bottom",
of: $("#save")
}
/*
Refer to: http://docs.jquery.com/UI/API/1.8/Position
*/
});
});
</script>