<html>
<head>
<meta charset="utf-8">
<title>Image profil</title>
</head>
<body>
<span id="pfl-img">
<span id="pfl-ini"></span>
</span>
</bo9dy>
</html>
#pfl-img {
display: block;
position: relative;
width: 45px;
height: 45px;
color: white;
font-family: Arial;
font-weight: bold;
font-size: 16px;
border-radius: 50%;
background-color: #333;
}
#pfl-img > #pfl-ini {
display: block;
position: absolute;
left: 50%;
top: 50%;
margin-left: -12px;
margin-top: -9px;
}
var colors = ['#226666', '#AA3939', '#AA6C39', '#2D882D'];
function getColor() {
var max = 3;
var min = 0;
var colorKey = Math.floor(Math.random() * (max - min)) + min;
console.log(colorKey);
var color = colors[colorKey];
return color;
}
function avatarGen(fst_name, lst_name) {
var pfl_img = document.getElementById('pfl-img');
var pfl_ini = document.getElementById('pfl-ini');
pfl_img.style.backgroundColor = getColor();
// Generate initials and insert DOM
var initials = /^\w/;
var fst_initial = initials.exec(fst_name);
var lst_initial = initials.exec(lst_name);
pfl_ini.innerHTML = fst_initial + lst_initial;
return 0;
}
(function() {
avatarGen("Ruan", "Aragão");
})();
Output
This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account
Dismiss xKeyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |