md-toolbar: allow fixed (sticky)
Hello,
This is more of a feature request.
I know there is a way to make toolbar appear and disappear as user scrolls via the use of md-scroll-shrink, but I'm wondering if there is a way to make toolbar fixed at the top so that it's visible at all times.
To be exact, I'm actually looking for a way to make the effect similar to the effect that can be observed on TV-Series app, where originally toolbar is large and has a background image, but as you scroll down the image disappears and the toolbar shrinks a bit.
I understand that the behavior described above is quite custom, and I'm ok writing custom code to achieve that, but for starters it'd be nice to have an easy way to make toolbar fixed at the top.
Perhaps it would make sense to create a new directive md-header (similar to how ionic is doing it) that would have fixed position by default and could potentially have an option to behave like described above.
Any help is appreciated, Thanks.
Do you mean something like this?
Yes! Very close! The TV-Series also has image appearing/disappearing as you do that scrolling, but the idea is the same. How did you achieve this?
Its from the specs of Material Design
Its a feature they didn't even talked about but i'm sure eventually they'll develop it.
opened an issue about it ##1054
Thanks for opening the issue!
By the way, it appears it's actually pretty easy to make toolbar fixed at the top. <md-toolbar> needs to be placed as the first element at the root of the <body> (I had it wrapped in a div, which is why it was not working).
Perhaps this could be placed in the documentation to avoid confusion.
@DmitryEfimenko Please post a code snippet or a working plunker. I am sure others will find it helpfull.
If anyone else needs to do this I have an example project go-material which I started working on to help people see how to structure an app. It doesn't do much right now but it does have a sticky header.
Any update on this missing feature?
@AMoQu My current fix for this is just to add a class to md-toolbar that implements position: fixed;
@wlingke do you have the example?
@infacq it's pretty easy to do it yourself... style="position: fixed;"
do you have example with the shrink one. I cannot get my head around it
No this does not do a shrinking one. You'll have to wait until it comes out. ᐧ
Best, Lingke
Lingke Wang Stanford GSB '16
On Wed, Jun 10, 2015 at 12:08 AM, Muhaimin [email protected] wrote:
do you have example with the shrink one. I cannot get my head around it
— Reply to this email directly or view it on GitHub https://github.com/angular/material/issues/1053#issuecomment-110624816.
Will be useful to have this this with the shrinking effect built in
I believe this is a good reference for this issue: http://codepen.io/jbltx/pen/KwQxBX
+1
I believe the use-case when you cannot put the <md-toolbar> as the first child element of the <body> is quite common and is the main source for the need for <md-toolbar> to be sticky inside other elements.
<body>
<ui-view></ui-view>
</body>
The loaded state (thus placed inside <ui-view>) might have the toolbar.
The proposed solution to just apply style position: fixed seems to be lacking given that one has to mess with css heights/margins also.
You can already have a fixed toolbar which isn't a direct child ofbody. You just need to add layout="column" to all of the parents of your toolbar.
I run into this problem with position fixed inside ui-view because if you ever have a backdrop (like dialog or select) the fixed position toolbar disappears.
Ideally we would do something like ionic - where you can specify it inside ui-view but it's rendered outside of it.
@guiporto I changed your code a little to fetch the background color of toolbar. Just replace the primary color with below code:
var reg = /\((\d+),*.(\d+),*.(\d+)/;
var bg = reg.exec($window.getComputedStyle(element[0], null).getPropertyValue('background-color'));
var primaryColor = [bg[1], bg[2], bg[3]];