Home > Web Front-end > JS Tutorial > JS method to set the absolute position of ff and ie elements_javascript skills

JS method to set the absolute position of ff and ie elements_javascript skills

WBOY
Release: 2016-05-16 15:11:40
Original
1256 people have browsed it

The example in this article describes how to implement JS to set the absolute position of ff and ie elements. Share it with everyone for your reference, the details are 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){ //用递归方法取值
  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;
}

Copy after login

Readers who are interested in more JavaScript-related content can check out the special topics on this site: "Summary of JavaScript search algorithm techniques", "Summary of JavaScript animation special effects and techniques", "Summary of JavaScript errors and debugging techniques", "Summary of JavaScript data structures and algorithm techniques", "Summary of JavaScript traversal algorithms and techniques" and "JavaScript Mathematics Summary of operation usage

I hope this article will be helpful to everyone in JavaScript programming.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template