How to make a mouse stalker

How to develope mouse stalker with JavaScript.

(function() {
    var doc = document;
    var body = doc.body;
    var stalker = doc.createElement("div");
    stalker.id = "stalker";
    stalker.innerHTML = '<img src="YOUR IMAGE PATH" alt="MouseStoker" width="70" height="70">';
    body.appendChild(stalker);

    body.addEventListener("mousemove", function(e) {
          stalker.style.left = e.clientX - 35 + "px";
          stalker.style.top = e.clientY - 80 + "px";
    }, false);

})()

This below code means adjest stalker image.
-35px is element harf width.
80 hieght position, you need adjest.

stalker.style.left = e.clientX - 35 + "px";
stalker.style.top = e.clientY - 80 + "px";

Then, make a style.

#stalker {
    position: fixed;
    transition: left 1.5s ease-in-out 0s, top 1.5s ease-in-out 0s;
    -webkit-transition: left 1.5s ease-in-out 0s, top 1.5s ease-in-out 0s;
    z-index: 9999;
}

関連記事