material icon indicating copy to clipboard operation
material copied to clipboard

md-toolbar: allow fixed (sticky)

Open DmitryEfimenko opened this issue 11 years ago • 44 comments

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.

DmitryEfimenko avatar Dec 26 '14 03:12 DmitryEfimenko

Do you mean something like this?

EladBezalel avatar Dec 26 '14 09:12 EladBezalel

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?

DmitryEfimenko avatar Dec 26 '14 09:12 DmitryEfimenko

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

EladBezalel avatar Dec 26 '14 10:12 EladBezalel

Thanks for opening the issue!

DmitryEfimenko avatar Dec 26 '14 10:12 DmitryEfimenko

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 avatar Dec 26 '14 18:12 DmitryEfimenko

@DmitryEfimenko Please post a code snippet or a working plunker. I am sure others will find it helpfull.

demisx avatar Dec 27 '14 16:12 demisx

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.

epelc avatar Dec 29 '14 01:12 epelc

Any update on this missing feature?

AMoQu avatar May 09 '15 17:05 AMoQu

@AMoQu My current fix for this is just to add a class to md-toolbar that implements position: fixed;

wlingke avatar May 22 '15 20:05 wlingke

@wlingke do you have the example?

infacq avatar Jun 10 '15 03:06 infacq

@infacq it's pretty easy to do it yourself... style="position: fixed;"

wlingke avatar Jun 10 '15 05:06 wlingke

do you have example with the shrink one. I cannot get my head around it

infacq avatar Jun 10 '15 07:06 infacq

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.

wlingke avatar Jun 10 '15 13:06 wlingke

Will be useful to have this this with the shrinking effect built in

noamamit92 avatar Jun 17 '15 06:06 noamamit92

I believe this is a good reference for this issue: http://codepen.io/jbltx/pen/KwQxBX

guiporto avatar Jul 12 '15 14:07 guiporto

+1

shinrox avatar Aug 21 '15 02:08 shinrox

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.

DmitryEfimenko avatar Aug 28 '15 23:08 DmitryEfimenko

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.

epelc avatar Aug 28 '15 23:08 epelc

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. 

wlingke avatar Aug 28 '15 23:08 wlingke

@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]];

ghahramani avatar Sep 12 '15 18:09 ghahramani