html - Display a child to outside its offscreen parent until parent appears wide enough -
let's have horizontally sliding menu toggles between being aligned to, , hidden beyond, left-hand side of browser window:
open (has class "open") closed (class "open" removed) +------+--------------+ +---------------------+ | | | | | | | | | | | | | | | | | | | | | | | | | +------+--------------+ +---------------------+
scss:
header nav[role="navigation"] { background: $primary-colour; bottom: 0; left: -282px; position: absolute; top: 0; width: 282px; @include transition(left 250ms cubic-bezier(0.645, 0.045, 0.355, 1.000)); &.open { left: 0; } }
now let's want toggle button either: 1) sits @ left of window while menu closed, , 2) sits inside menu, aligned right when open:
open closed +--+---+--------------+ +---+-----------------+ | | x | | | = | | | +---+ | +---+ | | | | | | | | | | | | | | | | +------+--------------+ +---------------------+
in addition, should honour menu's transition, aligns right-hand side @ point @ menu's visible width matches width of button. there way achieve css alone?
with little css jiggling, came solution:
// js illustrate animation $('.nav-toggle').click(function() { $('.nav').toggleclass('open'); });
.window { background: lightgrey; display: block; height: 200px; margin: 0 0 10px; overflow-x: hidden; position: relative; width: 400px; } .nav { background: blue; bottom: 0; position: absolute; top: 0; width: 0; -webkit-transition: width 250ms cubic-bezier(0.645, 0.045, 0.355, 1.000); -moz-transition: width 250ms cubic-bezier(0.645, 0.045, 0.355, 1.000); -ms-transition: width 250ms cubic-bezier(0.645, 0.045, 0.355, 1.000); -o-transition: width 250ms cubic-bezier(0.645, 0.045, 0.355, 1.000); transition: width 250ms cubic-bezier(0.645, 0.045, 0.355, 1.000); } .nav.open { width: 80px; } .nav-toggle-wrapper { height: 40px; float: left; min-width: 40px; width: 100%; } .nav-toggle { background: red; height: 40px; float: right; width: 40px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="window"> <div class="nav"> <div class="nav-toggle-wrapper"> <div class="nav-toggle"></div> </div> </div> </div>
also, see example on jsfiddle > link
Comments
Post a Comment