MooTools - Sticky menu

#bar{width:100%;background:#333;color:#fff;padding:20px}
#con{width:200px;height:1000px;background:#666}
window.addEvent('domready', function() {
if($('bar') != null){new NaMooSticky();}
}); 

var NaMooSticky = new Class({ initialize: function(){ this.bar = $('bar'); this.position_saver = this.bar.getPosition().y; window.addEvent('scroll',this.action.bind(this)); }, action: function(){ if (this.position_saver< window.getScroll().y){ this.bar.setStyles({'position':'fixed','top':0}); } else{ this.bar.setStyles({'position':'relative','top':0}); } } });
<div id='bar'>menu</div>
<div id='con'></div>