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

Persist across Browser sessions #58

Open
billiemead opened this issue Nov 14, 2024 · 1 comment
Open

Persist across Browser sessions #58

billiemead opened this issue Nov 14, 2024 · 1 comment

Comments

@billiemead
Copy link

I set up a Flipdown countdown timer to calculate how much time between when the CMS page is published and Midnight EST (when a callback changes a CSS class that removes an overlay).

    var now = new Date();
    var night = new Date(
        now.getFullYear(),
        now.getMonth(),
        now.getDate() + 1, // the next day, ...
        0, 0, 0 // ...at 00:00:00 hours
    );
    var timeUntilMidnight = night.getTime() - now.getTime();

Now, I'd like to use localStorage to make sure the countdown persists and keeps on ticking!

    // get timer offset (if not found, set to today)
        var now = new Date( localStorage.getItem('countdown-offset') || new Date() );

        // store the offset
        localStorage.setItem('countdown-offset', offset);

But when the count actually starts, wouldn't I want to use something like onUpdate ? Im actually not sure!

@PButcher
Copy link
Owner

I'm trying to understand your use case. FlipDown works by using a timestamp of some time in the future. If you know when your timer is due to end and store the original end-time in LocalStorage, when the user re-visits your page and the timestamp is retrieved from LocalStorage, the end time will still be the same and the counter will appear to have kept ticking while the user was away.

Did I misunderstand your use case?

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