Move the mouse pointer to a specific position?
So, I know this is an old topic, but I'll first say it isn't possible. The closest thing currently is locking the mouse to a single position, and tracking change in its x and y. This concept has been adopted by - it looks like - Chrome and Firefox. It's managed by what's called Mouse Lock, and hitting escape will break it. From my brief read-up, I think the idea is that it locks the mouse to one location, and reports motion events similar to click-and-drag events.
Here's the release documentation:
FireFox: https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API
Chrome: http://www.chromium.org/developers/design-documents/mouse-lock
And here's a pretty neat demonstration: http://media.tojicode.com/q3bsp/
changing position relative to mouse pointer
As per your question, the issue is that you're adding a new span everytime the mouse moves. I am guessing you only want to add it when mouse enters, and remove it once the mouse leaves.
I have tried to keep your code as much as possible and change only what is causing your issue.
document.querySelector("li a").addEventListener("mouseenter", (event) => {
let span; let alreadyHasSpan = event.target.childNodes.length > 1; //default length=1
if (!alreadyHasSpan) { span = $(`<span class="a-effect"></span>`); span.appendTo(event.target); }});
document.querySelector("li a").addEventListener("mousemove", (event) => { let targetLeftPos = event.target.getBoundingClientRect().left; if (event.target.childNodes.length > 1) { let span = event.target.childNodes[1]; $(span).css("left", `${event.clientX-targetLeftPos}px`); }});
document.querySelector("li a").addEventListener("mouseleave", (event) => { if (event.target.childNodes.length > 1) { let span = event.target.childNodes[1]; span.remove(); }});
a { position: relative;}
.a-effect { position: absolute; left: 0; height: 100%; width: 2%; background: black;}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<li class="nav-item active"> <a href="/" class="nav-link">Product</a></li>
Move the mouse pointer in a specific direction with unity
With the new input system (install via packagemanager) you can use
Mouse.current.WarpCursorPosition(...) (Input System version 1.0.0 as of nov 2020, or alternatively 1.1.0 preview 2).
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Mouse.html:
On desktop platforms (Windows, Mac, Linux, and UWP), you can move the mouse cursor via code. Note that this moves the system's actual mouse cursor, not just Unity's internally-stored mouse position. This means that the user sees the cursor jumping to a different position, which is generally considered to be bad UX practice. It's advisable to only do this if the cursor is hidden (see the Cursor API documentation for more information).
Related Topics
Document.Getelementbyid VS Jquery $()
How to Update/Upsert a Document in Mongoose
Draw a Circle Around Nodes Groups
Accessing JavaScript Variable from Ruby
Create an Array with Same Element Repeated Multiple Times
How Does Sort Function Work in JavaScript, Along with Compare Function
Detect If Browser Tab Has Focus
Rendering Raw HTML with Reactjs
Differencebetween Angular-Route and Angular-Ui-Router
How to Check for Null Values in JavaScript
Difference Between Throttling and Debouncing a Function
Is There an Equivalent of the _Nosuchmethod_ Feature for Properties, or a Way to Implement It in Js
How to Format a Float in JavaScript
Call Python Function from JavaScript Code
How to Mute All Sound in a Page with Js
Why Is String "11" Less Than String "3"
Target='_Blank' to Show in New Window, Not New Tab, Possible