[英]Fake position Fixed inside a Div but relative to window top, while scrolling
我必須通過給它一個絕對位置並使用jquery的scrollTop()為其賦予最高值,來在其容器內但相對於窗口偽造一個div的固定位置。 到目前為止,這似乎是一個不錯的解決方案,但固定效果僅適用於Chrome。 在firefox和ie10中,它緩慢移動,而在ie9中,它做一些振動
if ($.browser.webkit) {
//First I had to do some hack in order to get the scrollTop() same return in all browsers
var bodyPos = $('body').scrollTop();
}else{
var bodyPos = $('html, body').scrollTop();
}
//then I can calculate the point relative to the top of the window
var pos1 = $('#four').position().top;
var imgPos = bodyPos - pos1
$('#fixed1').css({'top': imgPos})
有人知道如何使這種效果成為跨瀏覽器嗎?
謝謝
我終於修復了,如您所見,在這種情況下,我想在滾動時為圖像在容器內設置一個假的固定位置。
好吧,奧卡姆的剃刀:
我為圖像創建了一個容器,並為其提供了一個絕對位置,寬度高度高度為100%,頂部為0。然后,將圖像設置為具有固定附件“ etvoilà”的容器的背景,此工作已完成。
有時這種事情會發生:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.