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

display: none breaks fitting #90

Open
TheOddler opened this issue Mar 14, 2023 · 2 comments
Open

display: none breaks fitting #90

TheOddler opened this issue Mar 14, 2023 · 2 comments

Comments

@TheOddler
Copy link

Hey!

I have a heading on a website that I'd like to fit, however, on small screen I split up the header in two lines. I do this by having one single line title, and a split up version:

<div id="title_full">
    MY TOOOOOOO LOOOOOONG TITLE
</div>
<div id="title_parts">
    <div id="title_part_one">MY TOOOOOOO</div>
    <div id="title_part_two">LOOOOOONG TITLE</div>
</div>

And then hiding them base on media queries:

#title_full {
      @media(max-width: $smart-header-cutoff) {
        display: none;
      }
     ...
}

#title_parts {
      @media(min-width: $smart-header-cutoff) {
        display: none;
      }
     ...
}

As scripts I have three fittys for each part.

This works great, but it seems to break fitty. It works fine when opening the website, but when rezising the window in such a way that it swaps between these two titlee the fitting breaks.

Is there some setting I should use to make this work?

@TheOddler
Copy link
Author

TheOddler commented Mar 14, 2023

So I just realised that display: none actually removed stuff from the DOM, and thus Fitty won't work (as per the readme). And apparently Fitty doesn't re-initialize when something is added to the DOM again, which I guess makes sense.

To solve this, instead of using display: none; I changed it to use

visibility: hidden;
height: 0;

That seems to have fixed it. I guess it's a bit more performance intensize, as you're resizing stuff even when it's not shown, but it works for now.

However, the question still stands, is there a way to make Fitty work together with display: none?

@rikschennink
Copy link
Owner

I don't think there currently is. This looks like a good workaround. You could additionally set pointer-events: none

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

No branches or pull requests

2 participants