Created
June 22, 2012 16:08
-
-
Save uzulla/2973741 to your computer and use it in GitHub Desktop.
Spacer.js
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
<html> | |
<head> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> | |
<script src="./spacer.js"></script> | |
</head> | |
<body onload="setSpacer('#FF0000');"> | |
<img src="spacer.js" width=100 height=100 alt=spacer><=This is Spacer!!!! | |
</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
<html> | |
<head> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> | |
<script src="./spacer.js"></script> | |
</head> | |
<body onload="setSpacer();"> | |
<img src="spacer.js" width=100 height=100 ><=This is Spacer!!!! | |
</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
/* | |
Spacer.min.js - client side spacer.gif | |
@uzulla | |
require jQuery | |
*/ | |
function setSpacer(color){ | |
var canvas = $('<canvas>')[0]; | |
$(canvas).attr("width", 1); | |
$(canvas).attr("height", 1); | |
var ctx = canvas.getContext("2d"); | |
if(color){ | |
ctx.fillStyle=color; | |
ctx.fillRect(0, 0, 1, 1); | |
}else{ | |
ctx.fillRect(0, 0, 0, 0); | |
} | |
var dataURL = canvas.toDataURL("image/png"); | |
$('img').filter('[src=spacer.js]').attr('src',dataURL); | |
} |
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
//spacer.min.js uzulla | |
function setSpacer(){$('img').filter('[src=spacer.js]').attr('src','data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///////wAAACH5BAEHAAIALAAAAAABAAEAAAICVAEAOw==');} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/uzulla/spacer.js