完美理解csss中offsetLeft,offsetWidth,scrollLeft区别。
来源:互联网 发布:人体辉光 知乎 编辑:程序博客网 时间:2024/05/29 03:30
本节内容旨在理解上述词的区别。
先来代码再分析
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title> <style type="text/css"> body{ margin-left: 30px; } .head{ width: 400px; height: 300px; background-color: #4ae75e; padding: 30px; border: 10px solid red; margin-bottom: 30px; } #but{ position: fixed; left:450px; top: 630px; } #cdc{ position: fixed; left: 60px; top: 500px; } #he{ width: 400px; height:100px; background-color: #4ae75e; overflow: auto; white-space: nowrap; } </style></head><body><div class="head" id="head"></div><div id="he" class="he"> CodePlayer 专注于编程开发技术分享 CodePlayer 专注于编程开发技术分享 CodePlayer 专注于编程开发技术分享 CodePlayer 专注于编程开发技术分享 CodePlayer 专注于编程开发技术分享 CodePlayer 专注于编程开发技术分享</div><div> <h1>head.offsetLeft:<span id="ab"></span><br></h1> <h1>head.offsetWidth:<span id="bc"></span><br></h1> <h1>he.scrollLeft:<span id="cd"></span></h1> <input type="button" value="点击" id="but"></div><script> var a=document.getElementById("head"); var ab=document.getElementById("ab"); var bc=document.getElementById("bc"); var cd=document.getElementById("cd"); var he=document.getElementById("he"); ab.innerHTML=a.offsetLeft; bc.innerHTML=a.offsetWidth; but.onclick=function () { cd.innerHTML = he.scrollLeft; }</script></body></html>
效果展示
结论
1.offsetLeft=距离浏览器左边的宽度
2.offsetWidth=2*padding+width+border*2;
3.scrollLeft=水平拖动条隐藏的内容长度。
0 0
- 完美理解csss中offsetLeft,offsetWidth,scrollLeft区别。
- offsetWidth、offsetHeight、offsetLeft、offsetTop以及scrollTop,scrollLeft的个人理解
- offsetTop.offsetLeft,offsetWidth,offsetHeight,offsetParent,scrollTop,scrollLeft,scrollWidth,scrollHeight区别
- offsetWidth、clientWidth、scrollWidth、offsetLeft、scrollLeft详解
- style.left,style.width与offsetLeft,offsetWidth、scrollLeft,scrollWidth的区别
- left、offsetLeft、width、offsetWidth区别
- offsetTop,offsetLeft,offsetWidth,offsetHeight,scrollLeft,scrollWidth,clientWidth详细
- clientWidth、offsetWidth、scrollWidth、clientLeft、offsetLeft、scrollLeft的测试Dome
- Web前端之 offsetWidth,clientWidth,scrollWidth,offsetLeft,clientLeft,scrollLeft
- offsetLeft,offsetTop,offsetHeight,offsetWidth,scrollTop,scrollLeft,scrollHeight,scrollWidth
- offsetWidth、offsetLeft、clientWidth、clientLeft、scrollWidth、scrollLeft各自特点比较
- clientWidth、offsetWidth、scrollWidth、clientLeft、offsetLeft、scrollLeft的测试Dome
- clientWidth、offsetWidth、scrollWidth、clientLeft、offsetLeft、scrollLeft的测试Dome
- offsetLeft,offsetWidth
- scrollLeft offsetWidth
- js 中offsetTop、offsetLeft、offsetWidth、offsetHeight详解
- JS:document.documentElement对象的clientWidth、offsetWidth、scrollWidth、clientLeft、offsetLeft、scrollLeft
- JS:body元素对象的clientWidth、offsetWidth、scrollWidth、clientLeft、offsetLeft、scrollLeft
- XML-网络传输协议
- UIButton文字居左,图片居右~Xib
- Linear Algebra - Lesson 7. 求解Ax=0: 主变量,特解
- SSH 使用EasyUI实现ZTee树状结构菜单
- 第七周项目2-建立链队算法库
- 完美理解csss中offsetLeft,offsetWidth,scrollLeft区别。
- Windows 驱动阻止进程创建
- Number类——包装类在向量vector类中的应用
- 代码优化之合理利用编译器
- 数据结构学习记录1
- 欧拉工程第三题 找出一个合数的最大质数因子
- Android开发艺术探索——第二章:IPC机制(中)
- java空指针问题
- Web前端性能优化的14条规则