
第一种:编辑代码:var odiv=documentgetElementById('divid');
alert(odivgetBoundingClientRect()left);
alert(odivgetBoundingClientRect()top);
第二种:编辑代码function CPos(x, y) {thisx = x; thisy = y;} / 得到对象的相对浏览器的坐标/ function GetObjPos(ATarget {var target = ATarget;var pos = new CPos(targetoffsetLeft, targetoffsetTop);var target =targetoffsetParentwhile (target posx += targetoffsetLeft posy += targetoffsetTop; target = targetoffsetParent }return pos; }var obj = documentgetElementById('divid') alert(GetObjPos(obj)['x'])//x坐标alert(GetObjPos(obj)['y'])//y坐标
SPAN 和 DIV 的区别在于,DIV(division)是一个块级元素,可以包含段落、标题、表格,乃至诸如章节、摘要和备注等。而SPAN 是行内元素,SPAN 的前后是不会换行的,它没有结构的意义,纯粹是应用样式,当其他行内元素都不合适时,可以使用SPAN
以上就是关于用js 获取一个div坐标的方法是什么全部的内容,包括:用js 获取一个div坐标的方法是什么、、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)