css - Transitions won't work when transform:translate3d combined with opacity -
on website have second header drifts down top when user scrolls down page. original header remains absolutely positioned @ top , scrolled out of sight second slides down.
due google chrome bounce scroll effect, if user scrolls when browser @ top of page, they're able see second header hanging around outside document. looks strange, , happens in chrome.
i've been trying make second header invisible when user scrolls top , slides out of view. have been attempting opacity value of 0 set ease
value. problem is, using transform:translate3d
animate slide-up / slide-down effect, , can't both opacity
, transform
work in same transition
rule.
ideally i'd following work, won't reason.
.hidden-header { position:fixed; transform:translate3d(0,-100%,0); background-color:red; width:100%; height:55px; opacity:0; transition: translate 0.3s, opacity 0s ease .3s; } body.header-dropdown .hidden-header { transform:translate3d(0,0,0); opacity:1; transition: translate .5s, opacity 0s; }
here jsfiddle show mean – https://jsfiddle.net/wbmm0kl7/2/
at moment have had set transition: .3s
means opacity fades in , out well, want avoid.
here picture of website problem on chrome trying solve. notice second header , nav menu visible when scrolling against edge of viewport/document.
here rest of code:
html
<header class="header">regular header</header> <div class="transform-container"> <div class="hidden-header">hidden header (slides down on scroll)</div> </div> <div class="content"></div> </div>
css html, body { height:100%; width:100%; margin:0; padding:0; }
.wrapper { background-color:orange; min-height:100%; } .header { position:absolute; width:100%; height:55px; background-color:pink; } .hidden-header { position:fixed; transform:translate3d(0,-100%,0); background-color:red; width:100%; height:55px; opacity:0; transition: .3s; } body.header-dropdown .hidden-header { transform:translate3d(0,0,0); opacity:1; transition: .5s; } .content { height:2000px; }
jquery jquery(document).ready(function($) {
$(window).scroll(function() { if ($(this).scrolltop() > 200) { $('body').addclass('header-dropdown'); } else { $('body').removeclass('header-dropdown'); } }); });
as per comment, have typo in css transitions rule. you cannot transition individual transform components. instead, use transition: transform 0.5s;
example.
to achieve effect of hidden header appearing immediately, set transition duration of opacity 0s when .header-dropdown
added. achieve effect of hidden header hiding after transform done transitioning, set transition delay of opacity transition duration used:
.hidden-header { position:fixed; transform:translate3d(0,-100%,0); background-color:red; width:100%; height:55px; /* delay opacity transition when returning ground state */ transition: transform 0.5s, opacity 0s 0.5s; opacity: 0; } body.header-dropdown .hidden-header { transform:translate3d(0,0,0); opacity: 1; transition: transform 0.5s 0s, opacity 0s; }
see fixed fiddle here: https://jsfiddle.net/teddyrised/wbmm0kl7/3/
note first numeric value of transition shorthand transition-duration
, while second numeric value transition-delay
Comments
Post a Comment