Skip to content

Sticky header#101

Open
Chrissy wants to merge 21 commits into
masterfrom
sticky-header
Open

Sticky header#101
Chrissy wants to merge 21 commits into
masterfrom
sticky-header

Conversation

@Chrissy

@Chrissy Chrissy commented Apr 27, 2017

Copy link
Copy Markdown
Contributor

It's a sticky header!

stickysticky

Comment thread src/templates/Header.html
@@ -1,96 +1,99 @@
<div class="header" id="header">

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh god this diff i'm sorry lol

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So AFAICT the diff looks 🍌 s here but pretty much the only change is the addition of the ref and dynamic -sticky class to the top level element, and the stuck header placeholder at the bottom, eh?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's true! just classic tabbing + diff disaster

Comment thread src/components/Header.js Outdated
}
},
mounted() {
const checkIfHeaderShouldBeSticky = function() {

@Chrissy Chrissy Apr 27, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this method pretty rigorously to make sure it doesn't make any unnecessary render calls. It only triggers an update when a) the header height changes (which is usually only twice) or b) the stickyness changes.

Comment thread src/components/Header.js Outdated
},
mounted() {
const checkIfHeaderShouldBeSticky = function() {
this.headerHeight = (this.$refs.header) ? this.$refs.header.clientHeight : null;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just a read so I think it is safe to call over and over again lol

@Chrissy

Chrissy commented Apr 27, 2017

Copy link
Copy Markdown
Contributor Author

ok @stuartsan this is about ready to go. Let me know what you think!

Comment thread src/components/Header.js
}
}
},
mounted() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we probably don't want to run this repeatedly in an interval....what about a debounced scroll handler, so it is responsive to the user's interaction but also not too inefficient/blocking because it won't execute on every single scroll event? Something like:

image

(I feel like it is probably ok to assume the header height is a fixed thing too rather than read it each time)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Might have to also add an event listener for touchmove, e.g. http://stackoverflow.com/a/9787064)

@Chrissy Chrissy Apr 27, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok yup! debounce is good. I've traditionally done something like that, but saw a vue implementation that used setInterval and thought it sorta made sense since sticky elements aren't expected to be super responsive.

But yeah you are probably right in retrospect that was maybe a ¯\_(ツ)_/¯ idea lol

@stuartsan stuartsan Apr 27, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, everything is a ¯\_(ツ)_/¯ idea 😁 Ok, cool.

text-align: center;
}

.header.-sticky {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One issue when hiding the branding and ending up with a new header height is that if you click on the filter events button, you end up with:

image

Where the height for the filters thing is set incorrectly

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dang! i even tested this menu but must have not done the right combo of things. I will fix!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok this is fixed!

@stuartsan

Copy link
Copy Markdown
Contributor

Overall this looks really nice and I dig the animation! I had just a couple comments, one bug and one idea for an improvement.

chrissy added 3 commits April 27, 2017 11:53
…ry time which is maybe bad and also the variables seem to be binding to window which is DEFINITELY bad
Comment thread src/components/Header.js
store.dispatch('setFilters',{zipcode: newZipcode });
}
},
headerHeight: function() {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not in love with this, but the header changes height several times as different assets come in, and setting it only once during mount isn't gonna be good enough. I'm open to better ideas though!

@Chrissy

Chrissy commented Apr 27, 2017

Copy link
Copy Markdown
Contributor Author

@stuartsan ok round 2 for your leisurely perusal. One controversial line in header.js, which I left a comment on.

@stuartsan

Copy link
Copy Markdown
Contributor

Ah, sorry @Chrissy ! I forgot to take a look at this, will look soon.

Comment thread src/components/Header.js Outdated
headerHeight: function() {
return (this.$refs.header) ? this.$refs.header.clientHeight : null;
},
checkIfHeaderShouldBeStuck() {

@stuartsan stuartsan May 7, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming nit / suggestion, since this is not just checking but also setting the header's stickiness or non-stickiness, maybe something like setStickyHeader vs checkIfHeaderShouldBeStuck?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good!

@stuartsan

Copy link
Copy Markdown
Contributor

@Chrissy , sorry for my delayed response here. I added a couple thoughts, overall it looks great. There are some conflicts in Header.html that I'm not sure how to resolve correctly -- if you wouldn't mind resolving those, let's merge this thang!

@Chrissy

Chrissy commented May 8, 2017

Copy link
Copy Markdown
Contributor Author

@stuartsan nice! I will fix the conflicts and address the comment this evening.

@Chrissy

Chrissy commented May 11, 2017

Copy link
Copy Markdown
Contributor Author

ok everything is conflict-free and I made that one change! @stuartsan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants