Last active
December 16, 2015 10:59
-
-
Save bryanbuchanan/5424480 to your computer and use it in GitHub Desktop.
Makes HTML5 canvas elements support @2x displays by doubling their size, then scaling them down to 50%. Requires jQuery.
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 | |
function retinaCanvas($canvas, context) { | |
$canvas.each(function() { | |
$(this).prop({ | |
width: $(this).width() * 2, | |
height: $(this).height() * 2 | |
}); | |
context.scale(2,2); | |
}); | |
} | |
// Usage | |
var $canvas = $('canvas'); // Define canvas element | |
var context = $canvas[0].getContext('2d'); // Define context | |
retinaCanvas($canvas, context); // Make @2x compliant |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment