Skip to content

Instantly share code, notes, and snippets.

@rakeshjuyal
Last active December 20, 2015 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rakeshjuyal/6068100 to your computer and use it in GitHub Desktop.
Save rakeshjuyal/6068100 to your computer and use it in GitHub Desktop.
Useless Snippet #2 ( Track focused element )
var focusedElemWrap = undefined;
$('.useless-focus-marker').remove(); //Uncomment if you want to reset
if ( $('.useless-focus-marker').length == 0 ){
$('<div class="useless-focus-marker">').css({
position:'absolute',
border:'1px solid rgba(100,100,200,0.7)',
'box-shadow':'0px 2px 12px rgba(50, 50, 50, 0.75)',
width:0,
height:0,
'z-index':9998,
'border-radius':'4px',
'background-color' : 'rgba( 50,150,250,0.2)',
opacity: 0.7
}).appendTo($('body'));
}
focusedElemWrap = $('.useless-focus-marker');
$('*').off('keyup.focustrack').on('keyup.focustrack', function(e){
if ( ( e.which == 9 ) && this == e.target ){
var self = $(this),
offset = self.offset(),
selfWidth = self.outerWidth(),
selfHeight = self.outerHeight(),
extraSpace = 12,
halfESpace = extraSpace / 2;
focusedElemWrap.stop().animate( {
left: offset.left - halfESpace ,
top: offset.top - halfESpace,
width: selfWidth + extraSpace ,
height: selfHeight + extraSpace } , 500 );
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment