2013-02-26 27 views
2

所有,我知道Draggable遏制選項可以設置字符串值與這些後續。jquery draggable遏制字符串值

Parent(限制拖動到當前元素的父元素的範圍內),windowdocument

但我不知道windowdocument值之間有什麼區別。我沒有發現這兩個值的任何api文件。請幫助我理解它。謝謝。

回答

1

這一切歸結爲difference between window and document。當您設置一個可拖動的containment,jQuery使用的其中一方的widthheight屬性來確定它的界限,爲the sources秀(格式化爲可讀性):

if(o.containment == 'document' || o.containment == 'window') this.containment = [ 
    0 - this.offset.relative.left - this.offset.parent.left, 
    0 - this.offset.relative.top - this.offset.parent.top, 
    $(o.containment == 'document' ? document : window).width() - 
     this.helperProportions.width - this.margins.left, 
    ($(o.containment == 'document' ? document : window).height() || 
     document.body.parentNode.scrollHeight) - this.helperProportions.height - 
     this.margins.top 
]; 

如果沒有iframe s,則我相信這兩個維度是相同的,否則,事情可能會有所不同(儘管我不確定jQuery是否支持在iframe之間拖放,即使來自同一個起源)。

+0

謝謝,mgibsonbr,我相信在大多數情況下這兩個設置是相同的。無論如何,我認爲'父'或'陣列'設置足夠使用。 – 2013-02-26 12:22:06