JS implements the method of setting the absolute positions of ff and ie elements

  • 2021-01-25 07:07:23
  • OfStack

This article shows how the JS implementation sets the absolute positions of ff and ie elements. To share with you for your reference, as follows:


function Show_menu(liid,divid)
{
  var li=document.getElementById(liid);
  var div=document.getElementById(divid);
  div.style.left=getLeft(li)+140+'px';
  div.style.top= getTop(li)+'px';
  var tt=div.style.top;
  div.style.display='block';
  alert(tt);
}
function getTop(e){ // I'm going to evaluate it recursively 
  var offset=e.offsetTop;
  if(e.offsetParent!=null) offset+=getTop(e.offsetParent);
  return offset;
}
function getLeft(e){
  var offset=e.offsetLeft;
  if(e.offsetParent!=null) offset+=getLeft(e.offsetParent);
  return offset;
}

More about JavaScript related content interested readers can view the site features: "JavaScript search algorithm skills summary", "JavaScript animation effects and skills summary", "JavaScript error and debugging skills summary", "JavaScript data structure and algorithm skills summary", "JavaScript eraser algorithm and skills summary" and "JavaScript mathematical operation usage summary"

I hope this article is helpful to JavaScript program design.


Related articles: