Вы можете использовать плагин jQuery PositionCalculator .
HTML:
<p><a class="lnkUsers" href="javascript:void(0)">Users Link1</a></p>
<p><a class="lnkUsers" href="javascript:void(0)">Users Link 2</a></p>
<p><a class="lnkUsers" href="javascript:void(0)">Users Link 3</a></p>
<p><a class="lnkUsers" href="javascript:void(0)">Users Link 4</a></p>
<p><a class="lnkUsers" href="javascript:void(0)">Users Link 5</a></p>
<p><a class="lnkUsers" href="javascript:void(0)">Users Link 6</a></p>
<p><a class="lnkUsers" href="javascript:void(0)">Users Link 7</a></p>
<p><a class="lnkUsers" href="javascript:void(0)">Users Link 8</a></p>
<p><a class="lnkUsers" href="javascript:void(0)">Users Link 9</a></p>
<div id="dvUsers" style="display:none; position:absolute; padding:10px; background:rgba(0,0,0,0.8); color:#ffffff">
I am the popup. <b>Click me to close</b>
<div class="dynamicInfo"></div>
</div>
JavaScript:
jQuery(function($) {
var $popup = $('#dvUsers');
var $infoField = $popup.find('.dynamicInfo');
function showPopup(event) {
// set content
$infoField.text('clicked link: ' + $(this).text());
// reset position
$popup.show().css({top: 0, left: 0});
// calculate new position
var calculator = new $.PositionCalculator({
item: $popup,
itemAt: "top left",
target: this,
targetAt: "bottom left",
flip: "both"
});
var posResult = calculator.calculate();
// set new position
$popup.css({
top: posResult.moveBy.y + "px",
left: posResult.moveBy.x + "px"
});
// window resize handler
$(window).off('resize.dvUsers');
$(window).on('resize.dvUsers', function(event) {
$popup.css({top: 0, left: 0});
var newResult = calculator.resize().calculate();
$popup.css({
top: newResult.moveBy.y + "px",
left: newResult.moveBy.x + "px"
});
});
}
// add click handler for show and hide
$('.lnkUsers').on('click', showPopup);
$popup.on('click', function() {
$popup.hide();
$(window).off('resize.dvUsers');
});
});
Вот пример в JSBin