offsetTop 与 style.top 的差别
我们知道 offsetTop 可以获得 HTML 元素间隔上方或外层元素的地位,style.top 也是可以的,二者的差别是:
一、offsetTop 返回的是数字,而 style.top 返回的是字符串,除了数字外还带有单位:px。
二、offsetTop 只读,而 style.top 可读写。
三、若是没有给 HTML 元素指定过 top 样式,则 style.top 返回的是空字符串。
offsetTop 与 style.top 的差别
我们知道 offsetTop 可以获得 HTML 元素间隔上方或外层元素的地位,style.top 也是可以的,二者的差别是:
一、offsetTop 返回的是数字,而 style.top 返回的是字符串,除了数字外还带有单位:px。
二、offsetTop 只读,而 style.top 可读写。
三、若是没有给 HTML 元素指定过 top 样式,则 style.top 返回的是空字符串。