offsetLeft到浏览器边用回溯替代的方法
来源:互联网 发布:双色球大赢家缩水软件 编辑:程序博客网 时间:2024/06/16 05:26
高程有错。
html代码:
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title> <!-- <meta http-equiv="X-UA-Compatible" content="IE=7"> --> <style> body { font-size: 12px; } #testId { color: white; width: 100px; height: 100px; background: gray; border: 10px solid red; border-width: 10px; margin: 10px; padding: 10px; } .outer { /*若注释掉下面这一行,会有不同效果哦*/ position: relative; border: 10px solid blue; margin: 50px; width: 400px; height: 400px; background: yellow; padding: 20px; } </style></head><body style="border-width: 0px;"> <div class="outer" style="border-width: 10px;"> <div id="testId" data-sqf="hei" style="border-width: 10px;"> <p></p> 我的宽高是100px,padding是10px,border是10px,margin是10px; </div> 我的宽高400px,margin 50px,border 10px ,padding 20px </div><script src="a.js"></script></body></html>
外部a.js的代码:
var oDiv = document.querySelector("#testId");// http://codepen.io/sqf/pen/NGgmzMfunction a(o){ var aa = o.offsetLeft; var p = o.offsetParent; while (p !== null){ // console.log(typeof parseInt(p.style.borderWidth)) console.log(aa); aa = aa + p.offsetLeft + parseInt(p.style.borderWidth); p = p.offsetParent; } return aa;}alert(a(oDiv));alert(oDiv.offsetLeft);
0 0
- offsetLeft到浏览器边用回溯替代的方法
- 跨浏览器的innerHTML.event.srcElment.offsetLeft
- 用图片替代滚动条的方法
- 替代goto的方法
- Externalizable 的替代方法
- 替代setLatestEventInfo()的方法
- 替代String.split("")的方法
- request.getRealPath()的替代方法
- request.getRealPath()的替代方法
- request.getRealPath()的替代方法
- request.getRealPath("") 的替代方法
- request.getRealPath()的替代方法
- getDrawable过时的替代方法
- 替代iframe的Jq方法
- getDrawable过时的替代方法
- ViewPager过时方法的替代
- okhttp3替代FormEncodingBuilder的方法
- getDrawable过时的替代方法
- 将java程序作为Windows服务
- 每天一个linux命令(11):nl命令
- C#异步跟踪exe输出并输出到RichTextBox
- KVO使用过程中的陷阱
- 多线程和多进程模型的选用
- offsetLeft到浏览器边用回溯替代的方法
- some useful tar options
- mvc简介
- 线程间通信
- DNS协议解析1--DNS请求协议
- C语言的标识符命名规则
- Codeforces #Round 321 Div2
- light1358 - Fukushima Nuclear Blast【圆与多边形面积的交+二分】
- 网站API自动化测试利器——Postman