項目中用的grunt-contrib-less, 寫了以下less代碼
.mapfix{ position: fixed; top:10px; width: 430px; z-index: 100; background: #fff; -position:absolute; -top:expression(eval(document.documentElement.scrollTop)); }
注意底部兩行是為了兼容IE6,即修復IE6的fixed。IE7+已經支持了。
執行less命令后,報錯
開始以為是less不支持IE css hack,后發現是IE css 表達式的問題,仕龍同學告知解決方法
-top: ~"expression(eval(document.documentElement.scrollTop+10));";
前面加個波浪號,后面用雙引號括起來。這時編譯通過。
相關:
http://www.lesscss.net/article/document.html
https://www.npmjs.org/package/grunt-contrib-less