Loading

Jquery 设置控件位置的方法

//javascript写法 
document.getElementById("child").style.left="800px"; document.getElementById("child").style.top="200px"; 
//jquery写法 
//offset()获取当前元素基于浏览的位置 
var offsettop=$("#unamespan").offset().top;
var offsetleft=$("#unamespan").offset().left; 
//position()获取当前元素基于父容器的位置 
var positiontop=$("#unamespan").position().top; 
var positionleft=$("#unamespan").position().left; 
//设置panel2的位置基于unamespan的坐标
 $("#panel2").css({position: "absolute",'top':offsettop+100,'left':offsetleft+50,'z-index':2});

  

posted @ 2016-07-29 10:32  3WLineCode  阅读(236)  评论(0编辑  收藏  举报