/**
* @param id
* @param clientX 相对窗口横坐标
* @param clientY 相对窗口纵坐标
* @param distance 滑动距离
*/
function dragandDrop(id, clientX, clientY, distance) {
var elem = document.getElementById(id),
k = 0,
interval;
iME(elem,"mousedown",0, 0, clientX, clientY);
interval = setInterval(function() {
k++;
iter(k);
if (k === distance) {
clearInterval(interval);
iME(elem,"mouseup",clientX + k, clientY, 220 + k, 400);
}
}, 10);
function iter(y) {
iME(elem,"mousemove",clientX + y, clientY, clientX + y, clientY);
}
function iME(obj,event,screenXArg,screenYArg,clientXArg,clientYArg){
var mousemove = document.createEvent("MouseEvent");
mousemove.initMouseEvent(event, true, true, window, 0, screenXArg, screenYArg, clientXArg, clientYArg, 0, 0, 0, 0, 0, null);
obj.dispatchEvent(mousemove);
}
}
window.setTimeout(function() {
obj = document.getElementById("card");
obj.target = '_self';
var _owh = obj.getBoundingClientRect();
var _ox=_owh.width/ 2,_oh=_owh.height/2;
_ox = Math.floor(Math.random() * _ox+60);
_oh = Math.floor(Math.random() * _oh+60);
_ox=_ox+_owh.x;
_oh=_oh+_owh.y;
dragandDrop("card",_ox,_oh,50);
}, 1000);
js模拟鼠标滑动
最新推荐文章于 2024-04-25 15:58:41 发布