欧美日韩国产一区二区|qovd片|小明个人发布看看|小浪货你夹真紧水又多|老头把我添高潮了A片故|99热久久精品国产一区二区|久久久春色AV

js怎么樣完美解決IE6不支持position:fixed的bug的方法?解決的方法分享

先來看段代碼

js怎么樣完美解決IE6不支持position:fixed的bug的方法?解決的方法分享

以上這段代碼在網(wǎng)上很常見,通過設置html{overflow:hidden}和body{height:100%;overflow:auto}來實現(xiàn)ie6下position:fixed效果 , 但這種辦法有個缺陷,那就是:這會使頁面上原有的absolute、relation都變成fixed的效果,在這里我就不做demo了 , 如果有懷疑,可以自己去試驗一下 。
于是我找了下資料,發(fā)現(xiàn)可以通過一條Internet Explorer的CSS表達式(expression)來完美的實現(xiàn)ie6下position:fixed效果,css代碼如下:
/* 除IE6瀏覽器的通用方法 */
.ie6fixedTL{position:fixed;left:0;top:0}
.ie6fixedBR{position:fixed;right:0;bottom:0}
/* IE6瀏覽器的特有方法 */
* html .ie6fixedTL{position:absolute;left:expression(eval(document.documentElement.scrollLeft));top:expression(eval(document.documentElement.scrollTop))}
* html .ie6fixedBR{position:absolute;left:expression(eval(document.documentElement.scrollLeft document.documentElement.clientWidth-this.offsetWidth)-(parseInt(this.currentStyle.marginLeft,10)||0)-(parseInt(this.currentStyle.marginRight,10)||0));top:expression(eval(document.documentElement.scrollTop document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)))}
上面代碼可以直接使用了,如果要設置元素懸浮邊距,要分別為設置兩次,比如我要讓某個元素距頂部10個像素 , 距左部也是10個像素,那就要這樣子寫:
/* 除IE6瀏覽器的通用方法 */
.ie6fixedTL{position:fixed;left:10px;top:10px}
/* IE6瀏覽器的特有方法 */
* html .ie6fixedTL{position:absolute;left:expression(eval(document.documentElement.scrollLeft 10));top:expression(eval(document.documentElement.scrollTop 10))}
這樣一來,IE6下實現(xiàn)position:fixed的效果解決了,而且也不會影響到其他的absolute、relation,但還有一個問題,就是懸浮的元素會出現(xiàn)振動
IE有一個多步的渲染進程 。當你滾動或調(diào)整你的瀏覽器大小的時候,它將重置所有內(nèi)容并重畫頁面,這個時候它就會重新處理css表達式 。這會引起一個丑陋的“振動”bug,在此處固定位置的元素需要調(diào)整以跟上你的(頁面的)滾動,于是就會“跳動” 。
解決此問題的技巧就是使用background-attachment:fixed為body或html元素添加一個background-image 。這就會強制頁面在重畫之前先處理CSS 。因為是在重畫之前處理CSS,它也就會同樣在重畫之前首先處理你的CSS表達式 。這將讓你實現(xiàn)完美的平滑的固定位置元素!
然后我發(fā)現(xiàn)background-image無需一張真實的圖片,設置成about:blank就行了 。
下面附上完整代碼
/* 除IE6瀏覽器的通用方法 */
.ie6fixedTL{position:fixed;left:0;top:0}
.ie6fixedBR{position:fixed;right:0;bottom:0}
/* IE6瀏覽器的特有方法 */
/* 修正IE6振動bug */
* html,* html body{background-image:url(about:blank);background-attachment:fixed}
* html .ie6fixedTL{position:absolute;left:expression(eval(document.documentElement.scrollLeft));top:expression(eval(document.documentElement.scrollTop))}
* html .ie6fixedBR{position:absolute;left:expression(eval(document.documentElement.scrollLeft document.documentElement.clientWidth-this.offsetWidth)-(parseInt(this.currentStyle.marginLeft,10)||0)-(parseInt(this.currentStyle.marginRight,10)||0));top:expression(eval(document.documentElement.scrollTop document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)))}
以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡 。
【js怎么樣完美解決IE6不支持position:fixed的bug的方法?解決的方法分享】

相關經(jīng)驗推薦