Created
October 21, 2010 16:39
-
-
Save Takazudo/638827 to your computer and use it in GitHub Desktop.
dom console
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
/** | |
* $.fixedConsole | |
* dom console | |
*/ | |
$.FixedConsole = function(){ | |
this.element = null; | |
this.max = 20; | |
}; | |
$.FixedConsole.prototype = { | |
init: function(){ | |
var $el = this.element = $('<ul />') | |
.css({ | |
margin: 0, | |
padding: 0, | |
listStyleType: 'none', | |
position: 'fixed', | |
right: 0, | |
top: 0, | |
opacity: 0.8, | |
padding: '1em 1em 0.5em', | |
background: '#000', | |
color: '#fff', | |
fontFamily: 'monospace', | |
minWidth: 300 | |
}) | |
.appendTo('body'); | |
return this; | |
}, | |
log: function(text){ | |
$('<li />') | |
.text(text) | |
.appendTo(this.element); | |
var lis = $('li', this.element).toArray(); | |
while(lis.length > this.max){ | |
$(lis.shift()).remove(); | |
} | |
return this; | |
} | |
}; | |
$.fixedConsole = new $.FixedConsole(); | |
/* go */ | |
$(function(){ | |
$.fixedConsole.init(); | |
$.fixedConsole.log('loglog yeah'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment