2013-05-17 75 views
0

我瞭解|,&,〜使用運營商,但我仍然無法解釋這些功能:FOCE佈局拖拽鼠標功能

function d3_layout_forceDragstart(d) { 
    d.fixed |= 2; 
} 
function d3_layout_forceDragend(d) { 
    d.fixed &= ~6; 
} 
function d3_layout_forceMouseover(d) { 
    d.fixed |= 4; 
    d.px = d.x, d.py = d.y; 
} 
function d3_layout_forceMouseout(d) { 
    d.fixed &= ~4; 
} 

回答

0

這些按位只是設置標誌位AND,OR和NOT 。如果您在d3 source code看看它們的使用進行了說明:

// The fixed property has three bits: 
// Bit 1 can be set externally (e.g., d.fixed = true) and show persist. 
// Bit 2 stores the dragging state, from mousedown to mouseup. 
// Bit 3 stores the hover state, from mouseover to mouseout. 
// Dragend is a special case: it also clears the hover state. 

function d3_layout_forceDragstart(d) { 
    d.fixed |= 2; // set bit 2 
} 

function d3_layout_forceDragend(d) { 
    d.fixed &= ~6; // unset bits 2 and 3 
} 

function d3_layout_forceMouseover(d) { 
    d.fixed |= 4; // set bit 3 
    d.px = d.x, d.py = d.y; // set velocity to zero 
} 

function d3_layout_forceMouseout(d) { 
    d.fixed &= ~4; // unset bit 3 
} 
+0

嘿感謝,我想我在尋找一個老版本,我沒有看到任何意見在那裏 – SOUser