简体   繁体   English

在jQuery中将div定位到按钮的右下角

[英]position a div to bottom-right of button in JQuery

I can set a div to top and left position of a button using following code: 我可以使用以下代码将div设置为按钮的顶部和左侧:

var p = $("#tag-add");
var offset = p.offset();
$("#TagModal").offset({ top: offset.top, left: offset.left})  

Output: 输出:

在此处输入图片说明

But I want to set the div to bottom right of button: 但我想将div设置为按钮的右下角:

在此处输入图片说明

How to do this? 这个怎么做?

Use this: 用这个:

$("#TagModal").offset({
  top: offset.top + p.outerHeight(),
  right: offset.left + p.outerWidth()
});

Try with this: 试试这个:

var p = $("#tag-add");
var offset = p.offset();

var $modal = $("#TagModal");
$modal.offset({
  top: offset.top + p.outerHeight(),
  left: offset.left + p.outerWidth() - $modal.outerWidth()
});

(Subtract width of the modal from @PraveenKumar's example) (从@PraveenKumar的示例中减去模态的宽度)

See this JSFiddle. 请参阅 JSFiddle。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM