第一个div是'#icon-selection-menu' bar,它的空闲位置是 absolute with top:0px 和 left:0px 。所以它出现在内容div的左上角。
The first div is the '#icon-selection-menu' bar, it's idle position is absolute with top:0px and left:0px. So it appears at he top left corner inside the content div.
在内容div的孩子,我得到其他div,其实是一种'.moticon-button'。他们的位置在他们的父母之间是相对的。在这样的按钮点击我想要定位的第一个div的按钮上方,调整它的底部边框到按钮的顶部边框。
Deep in the content div children I got other divs which are actually kind of '.emoticon-button'. Their position is relative inside their parent. On such button click I'd like to position the first div just above the button, adjusting it's bottom border to the button's top border.
如何获得顶部和左值设置 $('#icon-selection-menu' $('#icon-selection-menu')。left ?
推荐答案1 提供 .offset() / a>获取相对于文档的任何元素的位置。由于#icon-selection-menu 已经相对于文档定位,您可以使用:
jQuery1 provides .offset() to get the position of any element relative to the document. Since #icon-selection-menu is already positioned relative to the document, you can use this:
var destination = $('.emoticon-button').offset(); $('#icon-selection-menu').css({top: destination.top, left: destination.left});$('#icon-selection-menu')将放置在 $('。emoticon-button')的左上角。
(1)由于在问题中使用 $ ,jQuery假定。
(1) jQuery assumed due to the use of $ in the question.
更多推荐
如何使用javascript在另一个div的顶部定位一个div?
发布评论