Remove the animation when “docking” the menu #151
Conversation
Doesn't work as expected with a custom header image (which I couldn't get to work before due to having a blog on front) — will update tomorrow with a fix for this, too. |
Fixed the custom header issue — this is now ready for review. |
@ryelle After testing locally I am running into an issue where occasionally the menu stays fixed when scrolling back up. It doesn't happen every time, but if i scroll too fast it seems, it will behave like this. |
How strange. I was able to reproduce it, and it looks to be caused by the |
Working great now :) We just need to account for the 1px border. I am noticing a subtle shift when the menu docks because of it. |
@@ -17,15 +17,21 @@ jQuery( document ).ready( function( $ ) { | |||
// Make sure we're not on a mobile screen | |||
if ( 'none' === $( '.menu-toggle').css( 'display') ) { | |||
|
|||
$headerOffset = $( '.custom-header' ).innerHeight(); | |||
// When there's a custom header image, the header offset includes the height of the navigation | |||
$navigationHeight = $navigation.innerHeight(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To include border in height this should be
$navigationHeight = $navigation.outerHeight();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and also on line 48 within adjustHeaderHeight()
Just noticed that this sort of breaks on shorter pages. As you scroll down the site and the menu hits the top of the browser, it attempts to fix the header to the top of the window. On most pages this is fine, but on shorter pages when the menu is fixed, the page height gets decreased which makes the entire site fit inside of the browser window. When that happens it creates an impossible situation where the header wants to be both fixed at the top and in-line with the header at the same time. Here’s a rough screen cap: https://cloudup.com/cCBpdOsHhSv Best to try this out on your own. To replicate, create a page with just enough content to match the height of the entire header (with in-line menu). Then try and scroll down and you’ll see the how the menu gets confused and starts to jump around. |
Switched to @allancole I can't replicate what you're seeing. The page height doesn't change for me. What OS/browser are you using? |
@allancole I am able to reproduce that on master branch but not with this PR. You are using https://github.com/ryelle/twentyseventeen/tree/menu-animation ? |
@ryelle, Yeah it’s tough to explain properly, but I’ve run into a similar issue before in the past. I’m using the Chrome browser. But the issue also happens in Safari. See here: https://cloudup.com/cnvprFHlX0Y One thing I left out of the replicating instructions is that comments should be turned OFF, so that the page height is as short as possible. |
@josephfusco Yup, I pulled the code down from this PR.
|
Just to make sure - you did both steps, fetching the branch and checking it out?
|
Yup, I ran both of those commands. I can see the other improvements from this PR just fine, but this post (and one other like it) seem to show this one problem. Maybe if you download and import the theme unit test, you can take a look at that same “Clearing Floats” page and see if you see the same issue? |
@allancole I am using the "Clearing Floats" page of the theme unit test, removed footer widgets, added 3 rows of menu items, and am still not able to reproduce with this PR. I have looked at other pages too with shorter heights and played with the browser height trying to hit that sweet spot where scrolling ends and the menu just starts to hit the top of the viewport. 🤔 Possible cache? I know I already said this but this behavior is identical to
@davidakennedy Do you mind giving this a shot with trying to reproduce the behavior @allancole has mentioned? This is the only remaining issue I can see here. |
So odd that it isn’t happening for anyone else. I cleared my cache but it didn’t fix this for me. I’m on a 13in MBP so maybe screen size (or browser height) has something to do with it. Maybe try adjusting the height of the browser to make it smaller? I haven’t looked at the code, but since this only happening for me right now, maybe I can make a separate ticket for this and submit my own PR—assuming I can figure out a fix :-) |
b4c89da
to
4ab0957
Compare
Nothing new added ^, just rebasing on master. |
@ryelle The travis test is not passing. |
The offset includes the navigation height, so it wasn’t docking until the menu went offscreen. By subtracting the menu height when there’s a custom image, we dock the menu at the right scroll position.
Appears to be functionally duplicate to `site-navigation-fixed`, and is causing a “sticky menu” bug.
4ab0957
to
92a18a1
Compare
Fixed the |
Since we can't reproduce the edge case issue, I think this is ready to be merged and we can get more people using it to see if it comes up with anyone else.
@allancole that sounds good once this is in master if it is still happening on your end. |
Tested the PR and it looks good to me. Since it's a bigger one, I'm going to leave for @davidakennedy to take one last look at tomorrow. |
Thanks for the pull request @ryelle and for the excellent testing @josephfusco! @allancole I couldn't reproduce your issue, even after trying a feel "short" pages and resizing my browser to all kinds of heights. I'll keep this in mind as the theme is tested more though – just in case. |
I was chatting with @melchoyce about the menu docking on scroll, and we thought this was a smoother (less distracting) experience -- no bounce animation, and the menu stays the same height.
wp.org username: ryelle