Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix position when relative element become smaller #25

Merged
merged 2 commits into from
Aug 21, 2018
Merged

Fix position when relative element become smaller #25

merged 2 commits into from
Aug 21, 2018

Conversation

simonbrunel
Copy link
Contributor

Reset the affix position when the relative element height become smaller than the affix container and thus should be positioned on top. This case happens, for example, when the relative element contains dynamic (router) views and the affix element is on the side and acts similarly to vertical tabs.

@eddiemf I haven't been able to setup a jsfiddle to showcase that issue: it happens in a private project where the affix container is a side menu that changes the current route. The relative element contains a <router-view> and in some cases the current page has a smaller height than the affix element. With current version (v0.2.4), the affix element stay blocked to its last affixed position.

Reset the affix position when the relative element height become smaller than the affix container and thus should be positioned on top. This case happens, for example, when the relative element contains dynamic (router) views and the affix element is on the side and acts similarly to tabs.
@zamarawka
Copy link
Contributor

zamarawka commented Aug 21, 2018

@eddiemf actual pr for last updates.
I got this issue on refactored version.

@eddiemf
Copy link
Owner

eddiemf commented Aug 21, 2018

Thanks for the help :)

@eddiemf eddiemf merged commit 9a6afc3 into eddiemf:master Aug 21, 2018
@simonbrunel simonbrunel deleted the fix/position-dynamic-relative-el branch September 3, 2018 07:41
@@ -169,6 +169,12 @@ export default {
>= this.relativeElement.offsetHeight;

if (affixIsBiggerThanRelativeElement) {
Copy link
Contributor Author

@simonbrunel simonbrunel Sep 6, 2018

Choose a reason for hiding this comment

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

Actually, I think my change introduces another issue: when the element is hidden, this.relativeElement.offsetHeight === 0 and in that case we should not change the current state. What do you think about adding a check on this.relativeElement.offsetParent?

// ...
if (affixIsBiggerThanRelativeElement) {
  if (this.relativeElement.offsetParent) {
    if (this.scrollAffix && this.currentScrollAffix !== 'scrollaffix-top') {
      this.setScrollAffixTop();
    } else if (this.currentState !== 'affix-top') {
      this.setAffixTop();
    }
  }

  return;
}
// ...

or maybe that check should be on the overall affix logic:

onScroll() {
   //...
  this.updateData();

  if (!this.relativeElement.offsetParent) {
     // relative element not displayed
     return;
  }

  const affixIsBiggerThanRelativeElement = ...
  // ...
}

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.

3 participants