Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Themes & Styling

Dynamic counter

Started by bosse jonsen 6 years ago · 3 replies · 1666 views
6 years ago

Hi guys,

i want to create a dynamic counter. Something like this: http://demo.joomlead.com/particles/index.php/particles/simple-counter/ but without relying on gantry an particles.

Do you have an idea how to start?
Preferrably i would inpunt maximum count numbers somewher in the backend.. maybe exend the feature view of quark theme but instead of having a header i would have a number counting up from 0.

How can i realize the couting loop? Would it be good practice to to it via twig like in a for loop?
How could i realize the animation?

I am very pleased about your help.

5 years ago

Hi tom,
thank you for your hints.

My theme is a child of Quark 2.0.3
I managed to import the js from bfintal via base.html.twig

like so:

TWIG
    {% block javascripts %}
            ...
            {% do assets.addJs('theme://js/site.js', {group:'bottom'}) %}
            {% do assets.addJs('theme://js/waypoints.min.js') %}
            {% do assets.addJs('theme://js/jquery.countUp.min.js') %}
    {% endblock %}

I then created a new modular copying from modular/features.html.twig and also gave it a blueprint.
I got things up and running by calling the count function in site.js

JS
jQuery(document).ready(function ($) {
    // Count Up for Counters
    $('.counter').counterUp({
        delay: 50,
        time: 2000
    });
});

And it worked well. They counted up each time the pages was refreshed.

Bildschirmfoto 2020-12-21 um 16.19.51|690x193

After that i was wondering if i could influence each individual counter ind "delay" and "time" via a value given in the admin backend defined via blueprint.yaml

Bildschirmfoto 2020-12-21 um 16.24.00|426x499

How can i get the values from the backend into the site.js Javascript file in order to handle it in the function?

5 years ago

hmmm,

I would think you would need to parse the yaml file if possible or maybe use twig to pull the needed values and pass the information into the Javascript file.

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 196 2 months ago
Themes & Styling · by Ian, 2 months ago
3 92 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 452 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 46 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 126 3 months ago