Created
May 19, 2016 05:45
-
-
Save frumbert/b0d9f14cc288a7128c3e58a7c343ebe9 to your computer and use it in GitHub Desktop.
HoverThumb
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width,initial-scale=1"> | |
<title>title</title> | |
</head> | |
<body> | |
<p>HoverThumb: mouse over a link to see a full image preview. the href of the hyperlink points to the image.</p> | |
<p>Adjust as required.</p> | |
<a data-action="hover-thumb" href="http://i.imgur.com/0WmfqDk.jpg">Hover this link to preview its image</a></p> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script> | |
<script src="main.js"></script> | |
</body> | |
</html> |
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
$(function () { | |
$("a[data-action='hover-thumb']") | |
.hover(function(e) { | |
var img = $("<img>").attr({ | |
src: this.href, | |
id: "hoverThumb" | |
}).css({ | |
"position": "absolute", | |
"top": (e.pageY+10) + "px", | |
"left": (e.pageX+10) + "px", | |
"box-shadow": "0 0 25px rgba(0,0,0,.25)" | |
}); | |
$("body").append(img); | |
}, function () { | |
$("#hoverThumb").remove(); | |
}) | |
.mousemove(function(e) { | |
$("#hoverThumb").css({ | |
"top": (e.pageY+10) + "px", | |
"left": (e.pageX+10) + "px", | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment