2011-05-25 74 views
3

http://jsfiddle.net/mgJf2/2/受scrollTop影響的jQuery UI可拖動位置? (包括的jsfiddle)

包括jQueryUI的唯一的JavaScript之後是:

$("#scrollbox").draggable({ 
    axis: 'y', 
    drag: function(event, ui) { 
     $(document).scrollTop(ui.position.top); 
    }, 
}); 

文檔滾動複利已經在拖能夠DIV效果(我認爲有一個固定的位置)。它導致滾動失控。拿出文件滾動,它工作正常,只是沒有我想要的頁面滾動。

任何想法?

謝謝!

回答

1

我發現,使用拖動功能(火onmousemove),你可以抵消助手的位置。您必須在發佈的示例中指定助手 - 我想您只需替換ui.item就可以獲得ui.helper

drag: function(event, ui) { 
    var offset = $(this).offset(); 
    var yPos = offset.top; 
    ui.helper.css('margin-top', $(window).scrollTop() + 'px'); 
} 

這應該修復文檔在Chrome和Safari中滾動時的位置。沒有此修復程序,Mozilla是唯一正常工作的瀏覽器。沒有在IE上測試過。

乾杯

0

保持簡單。這是我的解決方案,它工作正常。

drag: function(event, ui) { 
    ui.helper.css('margin-top', -(t-c.scrollTop())); 
}, 
start: function(event, ui) { 
    t = c.scrollTop(); 
},