Moousture: 鼠标手势库
程序员文章站
2022-03-07 09:05:35
...
Zohaib Sibt-e-Hassan创造了一个基于Mootools的鼠标手势库-Moousture ,通过简单的鼠标运动就能进行导航。它的目标是为鼠标手势制定一个框架,在任何浏览器中都能使用,包括现代的移动设备。
它的核心很简单:
- probe(探针),定点设备。目前有Moousture.MouseProbe ;
- monitor(监控器),测试probed device的传递间隔和Moousture事件通知的稳定性(onStable, onUnstable, onMove);
- Moousture的记录类,用于记录鼠标的活动并调用guesture对象进行传递。
使用超级简单:
// Create a guesture matcher, currently there are only two gesture objects Moousture.LevenMatcher, and Moousture.ReducedLevenMatcher. gstr = new Moousture.ReducedLevenMatcher(); // Add gesture vectors to matcher object, (see details below in Create your own gestures). gstr.addGesture([3,2,1,0,7,6,5,4], ccwCircle); // Guesture callback function takes one parameter error recieved from matching algorithm. Threshold that value (if required) to make your gestures more sleek. function ccwCircle(error) { if(error>= 0.6) return; ... } // Create a probe object that will probe the pointing device. Currently there is a mouse probe that take the $(element) to probe for. So passing a div id will cause the probe to trigger events only when they occur on the passed DOM element. probe = new Moousture.MouseProbe($(document)); // Create a recoder object to record the movement , maxSteps and minSteps in options object will specify the maximum and minimum number of steps to be recorded, and macher is required matcher object to trigger the appropriate gesture. recorder = new Moousture.Recorder({maxSteps: 20, minSteps: 8, matcher: gstr}); // Create a monitor specifying the interval to poll and the amount of error allowed for gesture in pixels. monitor = new Moousture.Monitor(30, 2); // Finally start the monitor. monitor.start(probe, recorder); // You can stop the gesture triggering any time by calling .stop() of monitor object. monitor.stop();