A Pen by Captain Anonymous on CodePen.
Created
December 13, 2014 17:04
-
-
Save artemean/7200d7bef12800625032 to your computer and use it in GitHub Desktop.
XJdZOg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="asd"><div class="ms"></div></div> | |
<div class="coor"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(".asd").mousemove(function(e){ | |
var parentOffset = $(this).parent().offset(); | |
//or $(this).offset(); if you really just want the current element's offset | |
var relX = e.pageX - parentOffset.left; | |
var relY = e.pageY - parentOffset.top; | |
$(".coor").empty().append(relX, "-", relY); | |
var crds={ | |
left:relX, | |
top:relY | |
} | |
$(".ms").css(crds); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.asd {width: 500px; height: 200px; background: #ccc;} | |
.ms {position: absolute; width: 25px; height: 25px; background: #16f; border-radius: 15px; box-shadow: 3px 3px 5px #333; margin: -20px;} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment