Skip to content

Instantly share code, notes, and snippets.

@SomeoneWeird
Last active August 29, 2015 14:06
Show Gist options
  • Save SomeoneWeird/00e4a94dbe8acff691d0 to your computer and use it in GitHub Desktop.
Save SomeoneWeird/00e4a94dbe8acff691d0 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
var directions = {
'east': {
value: 1,
class: 'fromWest'
},
'southeast': {
value: 4,
class: 'fromNorthwest'
},
'south': {
value: 3,
class: 'fromNorth'
},
'southwest': {
value: 2,
class: 'fromNorthEast'
},
'west': {
value: -1,
class: 'fromEast'
}
}
$('.block').each(function() {
$(this).removeAttr('direction');
var dirs = $(this).attr('direction').split(' ');
var index = $('.block').index(this);
for(var i = 0; i < dirs.length; i++) {
var dir = dirs[i];
var direction = directions[dir];
if(!dir) {
$(this).append('<span class="arrow ' + dir + '"></span>');
}
var id = index + direction.value;
$('.block:eq(' + id + ')').append('<span class="arrow ' + direction.class + '"></span>');;
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment