Albeit, the above code is self explanatory, due to the presence of inline comments, but still for the depth view, here is a small description of the above code.
Now that we have the offset position of the element and mouse positions, we simply need to change the position of the element using the CSS property of the element. Make sure the styles are defined inline and the position of the element should be relative, otherwise the script will not work.
If you have any questions/comments, you can holla back by leaving a comment below.
Hope that helps.
Stay Digified !!