pqina / flip

⏳ The online version of the classic flip clock
https://pqina.nl/flip/
MIT License
892 stars 87 forks source link

d.getDays() ? #38

Closed nicmare closed 3 years ago

nicmare commented 3 years ago

Hi @rikschennink ! Tried to adapt your code to include days. Your code:

            Tick.count.down('2021-11-26T00:01:00', { format: ['h','m','s'] }).onupdate = function (value) {
                var d = Tick.helper.date();
                tick.value = {
                    hours: d.getHours(),
                    minutes: d.getMinutes(),
                    seconds: d.getSeconds()
                };
            };

my code:

            Tick.count.down('2021-11-26T00:01:00', { format: ['d','h','m','s'] }).onupdate = function (value) {
                var d = Tick.helper.date();
                tick.value = {
                    days: d.getDays(),
                    hours: d.getHours(),
                    minutes: d.getMinutes(),
                    seconds: d.getSeconds()
                };
            };

but then i get Uncaught TypeError: d.getDays is not a function. why does it not work?

rikschennink commented 3 years ago

Because getDays() doesn't exist on Date object, it's getDate() : ) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDate

Maybe use this template instead? https://pqina.nl/flip/preset-event-countdown.html

nicmare commented 3 years ago

i finally managed to build a nice appealing countdown. visually its perfect for my needs. but i am not sure if the code is correct. have the feeling it needs some optimization. What do you think? https://tvim.de/cheil/countdown/v3/billboard.html this is the code behind:

 Tick.count.down('').onupdate = function () {
            var d = Tick.helper.date();
            tick.value = {
                days: 16 - d.getDate(),
                hours: 24 - d.getHours(),
                minutes: 60 - d.getMinutes(),
                seconds: 60 - d.getSeconds()
            };
        };
rikschennink commented 3 years ago

I'll close the issue.

I'm not sure what you're trying to do there, again, I advise to look at the countdown example.

nicmare commented 3 years ago

thank you