直接讀取 offsetWidth 可能包含邊框,導致動畫寬度不精準。可改用 getStyle 取得 computed width,再轉成數字計算。
在舊版 IE 可用 currentStyle,其他瀏覽器則用 getComputedStyle。將兩者封裝成 getStyle,能讓動畫取值更穩定。
opacity 是 0 到 1 的小數,計算時可先乘以 100 當整數處理,最後再除回 100。同時要設定 filter 與 opacity,以相容不同瀏覽器。