当前位置:网站首页>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.

安全浏览器将拥有这些隐藏功能,让你玩转浏览器

单核浏览器和双核浏览器有什么区别,哪个好用?

siRNA-S-S-PEG-LMWP|M-MSN-siRNA介孔二氧化硅修饰RNA(齐岳RNA功能化修饰)

私域增长 | 私域会员:9大连锁行业15个案例集锦

腾讯安全发布 Tencent Cloud EdgeOne,为企业出海打造安全加速一体化服务

【AutoSAR 八 OS】

使用MD5加密后的字符串存密码安全吗?你不得不了解的Hash算法

leetcode:952. 按公因数计算最大组件大小【并查集】

叶酸&适配体修饰DNA纳米载体|CdS纳米颗粒修饰DNA|科研试剂
随机推荐
Common power symbols meaning sharing
双功能RGD-TAT修饰DNA纳米胶束|聚苯胺纳米线修饰DNA(PAINW/DNA)
easyExce模板填充生成Excel的实际操作,多sheet页处理
RNA修饰质谱检测|dextran-siRNA 葡聚糖化学偶联DNA/RNA|siRNA-PLGA聚乳酸-羟基乙酸共聚物修饰核糖核酸
Experience Sharing | Tips for Writing Easy-to-Use Online Product Manuals
ESP8266-Arduino编程实例-EEPROM读写
RNA的化学修饰原理|Gal-PEG-siRNA|siRNA-S-S-DSPE|siRNA-s-s-PEG|cholesterol-siRNA
sad rock
学校安全管理专题培训实施方案
数据可视化----网页显示温湿度
私域增长 | 私域会员:9大连锁行业15个案例集锦
Private domain growth | Private domain members: 15 case collections from 9 major chain industries
叶酸&适配体修饰DNA纳米载体|CdS纳米颗粒修饰DNA|科研试剂
[数学基础]概率论与数理统计相关概念学习
Detailed explanation of design ideas of webUI test framework
LeetCode_474_一和零
找工作那些事-和表弟的一次聊天
GNOME将在Secure Boot被禁用时向用户发出警告 并准备提供安全帮助
[数学]考研数学公式定理大总结
转行软件测试,你关心的都在这