在舊專案中,若要把返回頂部圖標固定在瀏覽器右下角,同時兼容 IE6,常會看到使用 CSS expression 的寫法。這種方式只適合維護老舊系統,現代專案建議改用 position: fixed 或 JavaScript 輔助。
#e_float {
_position: absolute;
_bottom: auto;
_right: 50%;
_margin-right: -536px;
_top: expression(eval(document.documentElement.scrollTop + document.documentElement.clientHeight - this.offsetHeight - (parseInt(this.currentStyle.marginTop, 10) || 0) - (parseInt(this.currentStyle.marginBottom, 10) || 0)));
}
其中底線前綴 _ 是針對 IE6 的 hack,expression 則讓元素位置能隨捲動重新計算。由於效能與維護性不佳,新專案不建議使用。