How to make smooth media-query transition back and forth? -
i've been digging day long , can't make work properly. i'm not coder, maybe that's problem. anyway, i'm trying make logo appear nicely when screen size changes. realize can't display:none; display:block; have tried visibility, opacity , height transition.
if @ code below, you'll see when going larger screen smaller, there's sort of delay appears before fading out, height animation plays. however, if go smaller window larger, transitions 2x faster. i'm not sure how make reverse, animation smooth going , forth. tried play numerous snippets web, nothing let's me control animation properly.
my idea hide logo on mobile devices, when ppl flip tablet, nice transition let logo appear larger screens (and not mobile, re-sizing desktop browser make more professional). hope can help.
.wrapper { width: 500px; background-color: #0c6; } .nav { background-color: #69c; } .logo { max-height: 0px; background-color: #fc3; -moz-transition: 1s; -o-transition: 1s; -webkit-transition: 1s; transition: 1s; visibility: hidden; opacity: 0; } @media screen , (min-width: 500px){ .logo { max-height: 200px; visibility: visible; opacity: 1; } } <!doctype html> <html> <head> <meta charset="utf-8"> <title>untitled document</title> </head> <body> <div class="wrapper"> <div class="logo">logo<br> <br> <br> <br> </div> <div class="nav">nav</div> </div> </body> </html>
you need transition on both ends, , transition value invalid:
.logo { max-height: 0px; background-color: #fc3; -webkit-transition: max-height 1s linear, opacity 1s linear; -moz-transition: max-height 1s linear, opacity 1s linear; -o-transition: max-height 1s linear, opacity 1s linear; transition: max-height 1s linear, opacity 1s linear; visibility: hidden; opacity: 0; } @media screen , (min-width: 500px){ .logo { max-height: 200px; visibility: visible; opacity: 1; -webkit-transition: max-height 1s linear, opacity 1s linear; -moz-transition: max-height 1s linear, opacity 1s linear; -o-transition: max-height 1s linear, opacity 1s linear; transition: max-height 1s linear, opacity 1s linear; } }
Comments
Post a Comment