动画/交互式鼠标指针



我正在尝试添加一个交互式鼠标指针,类似于此页面上的指针。我已经检查了很长一段时间的源代码,但根本无法弄清楚。

以与此页面相同的方式对鼠标指针进行动画处理需要什么代码?

缩小的代码在这里 - http://2f-design.fr/themes/starry/wp-content/themes/starry/js/header-pointer.js?ver=1.0

基本上,它只是一个画布,mousemove事件上带有事件侦听器,可以一遍又一遍地擦除/红行相同的星座

// Event handling
function addListeners() {
    if(!('ontouchstart' in window)) {
        window.addEventListener('mousemove', mouseMove);
    }
    window.addEventListener('scroll', scrollCheck);
    window.addEventListener('resize', resize);
}
function mouseMove(e) {
    var posx = posy = 0;
    if (e.pageX || e.pageY) {
        posx = e.pageX;
        posy = e.pageY;
    }
    else if (e.clientX || e.clientY)    {
        posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
        posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
    }
    target.x = posx;
    target.y = posy;
}

最新更新