Skip to content

Instantly share code, notes, and snippets.

@kaleb
Created October 11, 2013 18:43
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 kaleb/6939906 to your computer and use it in GitHub Desktop.
Save kaleb/6939906 to your computer and use it in GitHub Desktop.
.menu {
background-color:white;
border:1px solid red;
}
<!DOCTYPE html>
<html>
<head>
<script src="http://cdnjs.cloudflare.com/ajax/libs/knockout/2.2.1/knockout-min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<div id="view">
<button type="button" class="menu-toggle">
Toggle Menu
</button>
<div class="menu-container">
<ul data-bind="style: { display: expanded() ? 'block' : 'none'}" class="menu">
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
</div>
</div>
</body>
</html>
ko.applyBindings({
expanded: ko.observable(false)
}, view);
$('.menu-toggle').on('click', function () {
var expanded = ko.dataFor(this).expanded;
expanded(!expanded());
});
$('.menu').appendTo('body');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment