|
| 1 | +<!Doctype html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8"> |
| 5 | + |
| 6 | + <link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css"> |
| 7 | + <title>Scrollable: Dynamic Menus</title> |
| 8 | + |
| 9 | + <script src="http://code.jquery.com/jquery.js"></script> |
| 10 | + <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script> |
| 11 | + |
| 12 | + <script src="../jquery-ui-scrollable.js"></script> |
| 13 | + |
| 14 | + |
| 15 | +</head> |
| 16 | +<body> |
| 17 | + |
| 18 | +<div class="menu"> |
| 19 | + |
| 20 | + <nav class="navbar navbar-inverse navbar-fixed-top"> |
| 21 | + <ul class="nav navbar-nav nav-main"> |
| 22 | + <li class="active"><a href="#">Item 1</a></li> |
| 23 | + <li><a href="#">Item 2</a></li> |
| 24 | + <li><a href="#">Item 3</a></li> |
| 25 | + </ul> |
| 26 | + </nav> |
| 27 | + |
| 28 | + <nav class="navbar navbar-default navbar-static-top" style="margin-top: 50px; "> |
| 29 | + <div class="navbar-form navbar-left nav-search" style="top: 0; width: 50%; z-index: 2000;"> |
| 30 | + <div class="input-group"> |
| 31 | + <input type="text" class="form-control" placeholder="Search"> |
| 32 | + <span class="input-group-btn"> |
| 33 | + <button class="btn btn-default" type="button">Go!</button> |
| 34 | + </span> |
| 35 | + </div> |
| 36 | + </div> |
| 37 | + </nav> |
| 38 | + |
| 39 | +</div> |
| 40 | + |
| 41 | +<a href="https://github.com/bseth99/jquery-ui-scrollable"><img style="position: fixed; top: 0; right: 0; border: 0; z-index: 2000;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub"></a> |
| 42 | + |
| 43 | +<div style="position: fixed; right: 150px; top: 150px; width: 500px; margin: 10px; "> |
| 44 | + |
| 45 | + <div> |
| 46 | + <a href="../index.html">< Back to widget demos</a> |
| 47 | + </div> |
| 48 | + <br/> |
| 49 | + |
| 50 | + The demo illustrates how to use the Scrollable widget to create a dynamic menu that folds up/down as the page is |
| 51 | + scrolled. The content is setup in a way that the submenu slides behind the main menu and, once out of view, its |
| 52 | + contents become visible in the main menu bar. The solution does require calculating all the fixed positions |
| 53 | + of the menu items since they are not moved from their original parent. |
| 54 | +</div> |
| 55 | + |
| 56 | +<div style="height: 2000px;"> |
| 57 | +</div> |
| 58 | + |
| 59 | +<script> |
| 60 | +$(function () { |
| 61 | + $search = $( '.nav-search' ); |
| 62 | + |
| 63 | + $('.menu') |
| 64 | + .on('scrollin', function ( e, ui) { |
| 65 | + |
| 66 | + $search.css({ |
| 67 | + position: 'absolute', |
| 68 | + left: '0', |
| 69 | + width: '50%' |
| 70 | + }).parent().css( 'position', 'relative' ); |
| 71 | + |
| 72 | + }) |
| 73 | + .on('scrollout', function ( e, ui) { |
| 74 | + |
| 75 | + $search.css({ |
| 76 | + position: 'fixed', |
| 77 | + left: '230px', |
| 78 | + width: '30%' |
| 79 | + }).parent().css( 'position', 'static' ); |
| 80 | + |
| 81 | + }) |
| 82 | + .scrollable({ offset: { top: 50 } }); |
| 83 | + |
| 84 | +}); |
| 85 | +</script> |
| 86 | + |
| 87 | +</body> |
| 88 | +</html> |
0 commit comments