0
爲了省略我的應用場景,長話短說,我想要實現的就像是jQuery Slider,其中的錨點按等間隔拆分。當我移動光標並停在任意位置時,會有一個名爲FindNearestAnchor的方法觸發,並設置光標位置,並將其移動到最近的錨點。使用onmouseup設置元素位置到最近點不工作
我現在執行的是除了設置光標位置並將其移動到最近的錨點之外的所有內容。 Here是我參考的例子。
function _move_elem(e) {
//if set the nearest position here, the cursor will be stuck at the first anchor point.
selected.style.left = nearest[0];
selected.style.top = nearest[1];
}
function _destroy() {
//if set the nearest position here, nothing happened.
selected.style.left = nearest[0];
selected.style.top = nearest[1];
selected = null;
}
任何建議將不勝感激,非常感謝!
我使用的事件包是'onmouseup onmousemove onmousedown',我應該改爲'drag draop'嗎? –