2011-07-12 99 views
0

我有一個小小的椅子計劃。當我將鼠標懸停在椅子上時,我用jQuery製作了一個小小的彈出窗口。彈出窗口的位置基於我懸停的椅子的offset()jQuery動畫/偏移問題

但是,當我滾動時,彈出窗口仍保留在DOCUMENT中的相同位置,但它應該與我懸停的椅子對齊。

Here's an example

$(document).ready(function(){ 
    $(".sp_seat").live('mouseover', function() 
    { 
     var id = $(this).attr('id'); 

     var x = $(this).offset().left; 
     var y = $(this).offset().top; 

     $('#seat_'+id).css({"left":(x+30)+"px","top":(y+10)+"px"}); 

     $('#seat_'+id).fadeIn('fast'); 

    }); 

    $(".sp_seat").mouseout(function() 
    { 
     $('.username').fadeOut('fast'); 
    }); 

    $(".free").click(function() 
    { 
     var id = $(this).attr('id'); 
     window.location='?page=event/seatplan&action=pick&seat='+id; 
    }); 
}); 

這是我現在擁有的jQuery代碼。

在此先感謝。

回答

1

嗨,你應該能夠在您的ypos添加到頁面的滾動位置,

改變這一行:

$('#seat_'+id).css({"left":(x+30)+"px","top":(y+10)+"px"}); 

要:

$('#seat_'+id).css({"left":(x+30)+"px","top":(y+10)+$(document).scrollTop()+"px"}); 
+0

這似乎並沒有幫助。你能檢查一下嗎? http://bit.ly/nfNPV4 – Roel

+0

對不起,嘗試使用jquery position()而不是offset(),這將獲得相對於椅子而不是文檔的位置 – Gary