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

translateY and offsets #9

Closed
merijnponzo opened this issue Sep 6, 2023 · 3 comments
Closed

translateY and offsets #9

merijnponzo opened this issue Sep 6, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@merijnponzo
Copy link

merijnponzo commented Sep 6, 2023

Hi based on your theme.js within the src directory i think for example:

'fade-down': {
            '0%': {
                opacity: '0',
                transform: 'translateY(-2rem)',
            },
            '100%': {
                opacity: '1',
                transform: 'translateY(0)',
            },
        },

would not respect the original translateY value i guess like:

<div class="animate-fade-up w-20 h-20 translate-y-20 bg-slate-200 ">

you could add a utility class (offset.js)

module.exports = function ({ addUtilities, matchUtilities, theme }) {
const animateUtilities = matchUtilities(
    {
        'animate-y': (value) => {
            const spacingValue = theme('spacing')[value];
            const className = `animate-y-${value}`;

            return {
                [`--an-translate-y-${value}`]: spacingValue,
            };
        },
    },
    {
        values: Object.keys(theme('spacing')),
    }
)
}

then change theme.js to :

'fade-up': {
            '0%': {
                opacity: '0',
                transform: 'translateY(var(--an-translate-y))',
            },
            '100%': {
                opacity: '1',
                transform: 'translateY(var(--tw-translate-y))',
            },
        },

now the div slides from your new offset position class like (animate-y-40) to the orinal y value:

<div class="animate-fade-up w-20 h-20 translate-y-20 bg-slate-200 animate-y-40">
@e10a
Copy link

e10a commented Mar 30, 2024

Great work! I just wish there was a built-in way to use arbitrary values for more properties including offset positions.

@heidkaemper heidkaemper self-assigned this Apr 14, 2024
@heidkaemper heidkaemper added the enhancement New feature or request label Apr 14, 2024
@heidkaemper
Copy link
Member

@merijnponzo Sorry for the late reply. But indeed a good suggestion! We'll have a look what's possible.

@heidkaemper
Copy link
Member

With v1.1.0 this plugin now supports animation-composition utilities. With these we have a bit more control over intial values and offsets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

3 participants