jQuery:如何找到div中心的坐标 [英] jQuery : how to find the coordinates of center of a div
本文介绍了jQuery:如何找到div中心的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想得到一个div的中心坐标,根据这个div的中心定位另一个元素。 div实际上可以在屏幕上移动吗?
任何想法?
I want to get the coordinates of center of a divand position another element based on the center of this div. The div is actually movable on the screen ? Any ideas?
推荐答案
你应该将保证金设置为自动,因为它将居中(仅左和右)div在其父母内部。作为奖励,如果你想从顶部/底部居中,那么只需追溯父级的高度,除以2并将其用作顶部填充的值。示例: http://jsfiddle.net/VsqdW/2/
you should set margin to auto as this will center(left and right only) the div within its parent. as a bonus, if you want to center it from the top/bottom then just retrive the height of the parent, divide by 2 and use that as your value for top padding. example: http://jsfiddle.net/VsqdW/2/
这篇关于jQuery:如何找到div中心的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文