Created
April 4, 2014 05:44
-
-
Save icai/9968818 to your computer and use it in GitHub Desktop.
html5doctor ELEMENT effect
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
var links = $("#glossary li a"); | |
links.each(function() { | |
var linkWidth = $(this).outerWidth(); | |
var canvas = $("<canvas></canvas>"); | |
canvas.attr({width: linkWidth,height: 21}); | |
var context = canvas.get(0).getContext("2d"); | |
// Set up the rounded corners | |
context.lineWidth = 6; | |
context.lineJoin = "round"; | |
context.fillStyle = "#0090D2"; | |
context.strokeStyle = "#0090D2"; | |
// Draw the HTML5 Doctor logo | |
context.beginPath(); | |
context.moveTo(4, 10); | |
context.lineTo(8, 4); | |
context.lineTo(linkWidth - 9, 3); | |
context.lineTo(linkWidth - 3, 10); | |
context.lineTo(linkWidth - 10, 18); | |
context.lineTo(7, 16); | |
context.closePath(); | |
context.stroke(); | |
context.fill(); | |
var image = canvas.get(0).toDataURL("image/png"); | |
$(this).hover(function() { | |
$(this).css({background: "url('" + image + "') no-repeat"}); | |
}, function() { | |
$(this).css({background: ""}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment