javascript - 防止光标在旋转元素时进入某个区域?
问题描述
我正在使用 jQuery 可旋转来旋转页面上的元素。
但是,我想防止用户将光标拖向元素的中心。本质上,当用户试图向中心拖动时,鼠标指针应该沿着以目标元素中心为中心的圆滑动。
$('.element').rotatable({
handle: $('.element .handle'),
start: function( event, ui ) {
rotate_in_progress = true;
},
stop: function( event, ui ) {
rotate_in_progress = false;
},
rotate: function( event, ui ) {
//current mouse position
var mouse_pos = {
"x": event.clientX,
"y": event.clientY
};
var element_center = {
"x": parseInt($('.element').css("left")) + 0.5 * parseInt($('.element').css("width")),
"y": parseInt($('.element').css("top")) + 0.5 * parseInt($('.element').css("height"))
};
console.log(mouse_pos,element_center);
//TODO prevent mouse from moving within 20px of the center of the element; slide it along the edge of a circle with radius = 20px around the center in this case
}
});
当前小提琴:
解决方案
推荐阅读
- c# - 如何在 C# 中引用盒子碰撞器?
- jquery - next().focus() 仅适用于相同类型的控件
- javascript - IntersectionObserver 和位置:绝对
- flutter - 将一个类的方法拆分到不同的扩展有缺点吗?
- python - 正则表达式从 Python 中的文本中提取具有维度的数量
- javascript - 下载速度在本机反应中不起作用
- swift - Swift 包中的导入记录器仅在为 iOS 构建时会出错
- assembly - x86 VGA 中的双缓冲
- java - 类文件版本 54.0,Java Runtime 只有 52.0,同时尝试运行 docker
- java - 如何使用逗号分隔的字符串从特定列的列表中获取值