Skip to content

Instantly share code, notes, and snippets.

@bebraw
Created September 15, 2010 18:44
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 bebraw/581218 to your computer and use it in GitHub Desktop.
Save bebraw/581218 to your computer and use it in GitHub Desktop.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<title>Sidebar</title>
<script type="text/javascript" src="http://rightjs.org/hotlink/right-2.0.0.js"></script>
<script type="text/javascript">
var Generator = new Class({
_cur: 0,
initialize: function(items) {
this._items = items;
},
next: function() {
var ret = this._items[this._cur];
this._cur = this._cur + 1 == this._items.length? 0: this._cur + 1;
return ret;
}
});
var sidebar_offset = new Generator(['-100px', '0px']);
"#sidebar-handle".on('click', function() {
new Fx.Morph('sidebar-content').start({left: sidebar_offset.next()});
});
</script>
</head>
<body>
<div id="sidebar" style="width:120px;height:0px;background-color:blue">
<div id="sidebar-content" style="width:100px;height:200px;position:absolute;left:0px;top:0px;background-color:green">boz<div>
<div id="sidebar-handle" style="width:20px;height:200px;position:absolute;left:100px;top:0px;background-color:red">baz</div>
</div>
</body>
</html>
@kaievns
Copy link

kaievns commented Sep 15, 2010

$('content').morph({left: ($('content').getStyle('left').toInt() < 0 ? 0 : -100) + 'px'});

@bebraw
Copy link
Author

bebraw commented Sep 16, 2010

Thanks! That makes sense.

I guess another nice solution would be to use a generator. Interestingly JS 1.7 provides support for them (https://developer.mozilla.org/en/New_in_JavaScript_1.7).

@bebraw
Copy link
Author

bebraw commented Sep 20, 2010

I settled for a generator based implementation. Btw the code works great in Chrome now. :)

@kaievns
Copy link

kaievns commented Sep 20, 2010

Excellent! I see you're having fun 8)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment