当前位置:网站首页>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
边栏推荐
猜你喜欢
安全浏览器将拥有这些隐藏功能,让你玩转浏览器
There is a fee for the picture bed software. Forget it, I wrote an open source free one.
解决宝塔mysql 远程root 无法连接问题
【体系结构 一 概述】
JMeter使用教程(一)
JMeter usage tutorial (2)
RNA的化学修饰原理|Gal-PEG-siRNA|siRNA-S-S-DSPE|siRNA-s-s-PEG|cholesterol-siRNA
【体系结构 三 流水线技术】
转行软件测试,你关心的都在这
GalNAc-siRNA甘露糖/半乳糖修饰脱氧核糖核酸|siRNA-S-S-DSPE(RNA修饰技术介绍)
随机推荐
Single-core browser and what is the difference between dual-core browser, which to use?
Samba server configuration (when a server is required)
简单说说K均值聚类
ESP8266-Arduino programming example-EEPROM read and write
藻酸盐/PEI/DNA复合载体|脂质-鱼精蛋白-DNA复合物|合成方法
Expert advice | How to formulate a growth strategy for survival in an economic downturn
offsetwidth111[通俗易懂]
ACM学习书籍简介
正则表达式
单核浏览器和双核浏览器有什么区别,哪个好用?
Detailed explanation of design ideas of webUI test framework
【体系结构 三 流水线技术】
Hyaluronic acid-siRNA透明质酸修饰核糖核酸|peptide–siRNA 多肽偶连RNA/DNA核酸(齐岳PNA修饰物)
万字总结:分布式系统的38个知识点
正则表达式
【AutoSAR 十二 模式管理】
conda虚拟环境 | install 与 list 问题
Build your own image search system (1): 10 lines of code to search images by image
In the past six months, I have done those things about the automatic return of the transaction link...
Sasser virus source code (ransomware source code)