Created
June 25, 2016 04:55
-
-
Save bigomega/9bc7c89294d951f24631a53104e92e63 to your computer and use it in GitHub Desktop.
render a hexagon of elements in DOM
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 hex_arrangement = [ | |
'3333', | |
'32223', | |
'321123', | |
'3210123' | |
] | |
var hexval = { | |
0: [['profile', 'data-nav="home']], | |
1: [ | |
['behance', 'https://www.behance.net/bigOmega'], | |
['github', 'https://github.com/bigomega/'], | |
['twitter', 'https://twitter.com/bigomega'], | |
['medium', 'https://medium.com/@bigomega/'], | |
['mail', 'mailto:[email protected]'], | |
['flickr', 'https://www.flickr.com/photos/bigomega/albums'] | |
], | |
2: [ | |
['deviantart', 'http://bigomega.deviantart.com/'], | |
['codepen', 'http://codepen.io/bigomega/'], | |
['stackoverflow', 'http://stackoverflow.com/users/2130750/bigOmega'], | |
['steam', 'https://steamcommunity.com/id/bigomega'], | |
['tumblr', 'http://big0mega.tumblr.com'], | |
// ^ OR | |
// ['quora', 'https://www.quora.com/profile/Bharath-Raja'] | |
['facebook', 'https://www.facebook.com/big0mega'], | |
['reddit', 'https://www.reddit.com/user/big0mega/'], | |
['skype', 'skype:bigOmega3?chat'], | |
['youtube', 'https://www.youtube.com/c/bigomega'], | |
['linkedin', 'https://www.linkedin.com/in/bigomega'], | |
['vine', 'https://vine.co/bigomega'], | |
['instagram', 'https://instagram.com/big0mega/'] | |
], | |
count: { 0: 0, 1: 0, 2: 0 }, | |
} | |
$('.hive').html((new Array(8)).join(1).split('').reduce(function(mem, x, ind) { | |
// console.log('-------L', ind, line_count) | |
var line_count = ind < 4 ? ind + 4 : 3 + 7 - ind | |
return mem + '\ | |
<div class="line">\ | |
' + | |
(new Array(line_count + 1)).join(1).split('').reduce(function(mem2, y, ind2) { | |
var level = hex_arrangement[line_count - 4][ind2] | |
var val = hexval[level] ? hexval[level][hexval.count[level]++] : '' | |
// console.log(level) | |
return mem2 + '\ | |
<'+(val ? 'a' : 'div')+' class="hex-container level-'+ level +' '+ (val ? 'icon ' + val[0] : '') +'" target="_blank" '+(val ? (level != 0 ? 'href="' : '') + val[1] + '"' : '')+'>\ | |
<div class="hex-border"><div class="hex"><span></span></div></div>\ | |
</'+(val ? 'a' : 'div')+'>\ | |
' | |
}, '') | |
+ '\ | |
</div>\ | |
' | |
}, '')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment