使用 onmouseup 将元素位置设置为最近点不起作用
Using onmouseup set element position to nearest point not work
为了长话短说我的应用场景,我想要实现的是类似于 jQuery 锚点按等间隔分割的滑块。当我移动光标并停在任意位置时,触发了一个名为FindNearestAnchor
的方法,并设置光标位置,并将其移动到最近的锚点。
我现在实现的是除了设置光标位置并将其移动到最近的锚点之外的所有内容。 [这里][1]是我参考的例子。
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;
}
任何建议将不胜感激,非常感谢!
[1]: https://jsfiddle.net/tovic/Xcb8d/
我将这些代码移到了 AngularJS 指令中,它对我来说工作得很好。
link:{
init: function (scope, element, attrs, ngModel) {
function _move_elem(e) {
...
}
function _destroy() {
}
}
}
为了长话短说我的应用场景,我想要实现的是类似于 jQuery 锚点按等间隔分割的滑块。当我移动光标并停在任意位置时,触发了一个名为FindNearestAnchor
的方法,并设置光标位置,并将其移动到最近的锚点。
我现在实现的是除了设置光标位置并将其移动到最近的锚点之外的所有内容。 [这里][1]是我参考的例子。
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;
}
任何建议将不胜感激,非常感谢! [1]: https://jsfiddle.net/tovic/Xcb8d/
我将这些代码移到了 AngularJS 指令中,它对我来说工作得很好。
link:{
init: function (scope, element, attrs, ngModel) {
function _move_elem(e) {
...
}
function _destroy() {
}
}
}