当前位置:网站首页>offsetwidth111[easy to understand]
offsetwidth111[easy to understand]
2022-07-29 20:56:00 【Full stack programmer webmaster】
Hello everyone, we meet again, I'm your friend Quanstack Jun.
offsetwidth includes border, padding, etc., that is, the size of the box model.(So when offsetWidth and border appear at the same time, consider whether it will cause errors) A small experiment When the width and height of the div is 200px and the border is 1px, add a narrower to the divWhen the timer event is used, use the statement: div.style.width = div.offfsetWidth -1+'px', you will find that the div is getting wider.The reason: style.width is 200 without a doubt, but offsetWidth is (200+1+1)=202, so after the first statement execution, style.width = 202-1+'px'=201px; that's why the div gets wider, the next second and third execute and so on.
Solution: ① A more tedious solution is to set the width in the interline style of the div, and then change it to parseInt (div.style.width) on the right side of the assignment statement, which can also complete the function implementation.②The method of obtaining style through encapsulation, when there is an interline style, the data between the lines is obtained, and when it is in the style sheet, the value of the width in the style sheet is obtained.
function getStyle(obj,name){ //packages a function, to resolve compatibility issues with different browsersif(obj.currentStyle){return obj.currentStyle[name]; //currentStyle is only compatible with IE, not compatible with Firefox and Google}else{return getComputedStyle(obj,false)[name];//getComputedStyle is compatible with Firefox and Google, not IE//JS motion application-1}}Publisher: Full-stack programmer, please indicate the source: https://javaforall.cn/129592.htmlOriginal link: https://javaforall.cn
边栏推荐
- Kubernetes: (4) Common commands
- 【Autosar 启动流程详解】
- 私域增长 | 私域会员:9大连锁行业15个案例集锦
- [GXYCTF2019]禁止套娃
- 小学弟问:程序员的工作是不是每天都是敲一天的代码呢?
- 通过观测云监控器监控基础资源,自动报警
- [mathematical foundation] probability and mathematical statistics related concept learning
- 转行软件测试,你关心的都在这
- conda虚拟环境 | install 与 list 问题
- 聚丙烯微孔膜的等离子体改性及DNA|有机自由基改性DNA-阳离子脂质复合体的应用
猜你喜欢

HMS Core音频编辑服务音源分离与空间音频渲染,助力快速进入3D音频的世界

4D Summary: 38 Knowledge Points of Distributed Systems

使用IDEA连接mysql

程序员如何提升自己写代码的能力?

Verilog的时间格式系统任务----$printtimescale、$timeformat

【Autosar vLinkGen 链接器脚本生成器】

【组成原理 五 系统总线】

ACM study book introduction

Thesis writing strategy | how to write an academic research paper
![[数学基础]高等数学相关概念学习](/img/59/3e1608de63c60201b3e7aaaf032d42.png)
[数学基础]高等数学相关概念学习
随机推荐
[数学基础]高等数学相关概念学习
【AutoSAR 六 描述文件】
Omni-channel e-commerce | How can well-known domestic cosmeceuticals seize the opportunity to achieve rapid growth?
敏捷组织 | 企业克服数字化浪潮冲击的路径
Experience Sharing | Tips for Writing Easy-to-Use Online Product Manuals
Monitoring basic resources through observation cloud monitor, automatic alarm
RNA修饰技术介绍|介孔二氧化硅纳米颗粒(MSN)搭载的微小RNA-24(miR-24)纳米载体复合物
Briefly talk about K-means clustering
百度实习学弟深夜吐槽:原来大厂是这种生活啊
Internship: use easypoi to import and export excel table data
LeetCode_474_一和零
es6语法使用默认参数和解构
regular expression
正则表达式
单核浏览器和双核浏览器有什么区别,哪个好用?
图床软件要收费,算了我自己写一个开源免费的。
[数学]线性代数复习总结
C language learning books zero-based introductory articles
单壁碳纳米管-DNA复合物(SWCNT-DNA)|作用机理
EasyExce template filling generation of Excel of actual operation, many processing sheet page