I am looking for a solution on how to set the position of a popup div that is displayed by clicking on another div, but its position depends on where the position of the window is.
Here are some examples of my divs:
<div id="header"></div>
<div id="open">Click here to open the popup</div>
<div id="popup">
<div class="popup-wrapper">
<div class="content">
<h1>TEST</h1>
</div>
</div>
</div>
<div id="footer"></div>
For instance:
If the user clicks on the #opendiv to show the div #popupwith the scroll bar position of the browser window at the bottom, I want the #popupdiv to appear at the top of the #opendiv.
However, if the user clicks the div '#open' to show the div #popupwith the position of the browser window on top, I want the #popupdiv to appear at the bottom of the #opendiv.
Here is the script I used:
$("#popup").click(function(e) {
if ($(e.target).closest(".content" ).length > 0){
return false;
}
$("#popup").fadeOut(200);
$("body").addClass("no-scroll");
});
$('#open').click(function() {
$("#popup").show();
});
Here is the complete css code with FIDDLE