A Pen by Nikita Verkhoshintcev on CodePen.
Created
April 29, 2016 08:30
-
-
Save Frelseren/ef2fd735f6ff0de36057281368ae5c52 to your computer and use it in GitHub Desktop.
img-tagging
This file contains hidden or 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
<html> | |
<head></head> | |
<body> | |
<div class="img-wrapper"> | |
<img src="https://i.ytimg.com/vi/GMkDBh1NnP0/maxresdefault.jpg" /> | |
</div> | |
</body> | |
</html> |
This file contains hidden or 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
$('.img-tag').hide(); | |
$('img').click(function (e) { | |
const OFFSET = $(this).offset(); | |
const NUM = $('.img-tag').length + 1; | |
const IMG_WIDTH = $(this).width(); | |
const LEFT_OFFSET = e.pageX - OFFSET.left + 'px'; | |
const TOP_OFFSET = e.pageY - OFFSET.top + 'px'; | |
console.log(LEFT_OFFSET); | |
console.log(TOP_OFFSET); | |
$(this).after(function() { | |
return '<span class="img-tag" style="left:' | |
+ LEFT_OFFSET | |
+ ';top:' | |
+ TOP_OFFSET | |
+ ';">' | |
+ NUM | |
+ '</span>'; | |
}); | |
}); |
This file contains hidden or 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
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script> |
This file contains hidden or 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
img | |
max-width: 100% | |
cursor: crosshair | |
.img-wrapper | |
position: relative | |
.img-tag | |
position: absolute | |
background: red | |
color: white | |
padding: 3px 9px | |
border-radius: 100px | |
transform: translate(-50%) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment