8/22/2021

Counteranimated Number Counter For Your Website

53

Cool animations and clever microinteractions are all the rage right now. However, most developers know how long and tedious it can be to constantly write and rewrite CSS animations. It can start to feel like you're reinventing the wheel. Wouldn't it be nice to have a library of common animations that you can pull from anytime for any of your projects?

Table of Contents

Statcounter provides customisable hit counters, visitor tracking, web analytics and website stats for Tumblr. Sign up for an account at Statcounter to get your code. These instructions will be repeated after you've created an account and added your first project. Apr 02, 2019 Adding a pre-built counter. If you prefer to add a pre-built counter to your web page, here are a few ways to do so. Check with the web host for your web page. Often the company hosting your web page offer free solutions and provide instructions on how to add the counter code to your web page.

Enter Animate.cssA collection of 'just-add-water CSS animations' created by Daniel Eden

With Animate.css, you can easily animate any element with only one line of code. But, if you need to get a little more fancy, it also offers quite a few customization options. In this tutorial, we'll learn how to use Animate.css by building a one page website. Let's get started!

Getting Started

There are two ways to get up and running with Animate.css. The first way is to download it from the official website. Once you've done this, all you have to do is add it to your project folder and link to it in your HTML.

*Note: Animate.css contains only one file! This minimizes load time and keeps everything simple.*

The second option for getting started is to use a CDN. You can find this here. Once you've got it, you can link to it just like before:

And, that's it! No more setup is necessary to begin using all the awesome animations that come with Animate.css. All we have to do now is add some water..

Static Animations

The first thing we will do is a simple static animation that activates right when the page loads. Obviously, this animation will have to be at the top of the page - unless it repeats over and over. So, we'll start off with a full screen hero element and animate the text inside when the page is loaded. Here's the basic HTML we need:

Now, all we need to do to animate the two headings is give them the animated and bounceInDown classes. The first class is necessary to use any Animate.css animation. But, the second class is just one of many options we could use here. The official Github docs have a full list of animations you can use.

This is nice, but we can definitely expand on it. Let's add an arrow at the bottom of our hero that bounces continuously to let the user know they can scroll down. We'll give this element two classes: animated and bounce.

As we have it right now, this animation will only happen once. However, there are three CSS properties you can use to control this animation. They are:

  1. animation-duration
  2. animation-delay
  3. animation-iteration-count

For our purposes, we only need to use the first and the third to slow down the animation and make it infinite. Thus, our final markup for the first section look's like this:

*Note: Most of the CSS in these examples has been omitted for the sake of clarity. Check out the full demo for the arrow styles, etc.*

And, here's the CSS that makes the magic happen ad infinitum:

And, here's a pen showing it all in action:

As you can see, it's super simple to do these static animations. In the next section, we'll add some complexity by using jQuery to dynamically trigger Animate.css.

Scroll Animations

The first type of dynamic animation we'll look at is a scroll animation. With a little bit of jQuery we can check to see if an element is in the viewport. Then, all we have to do is add our Animate.css classes to it. We'll use three blocks of text, each with an icon, to demonstrate this. Here's the markup:

Now we can use jQuery to check see if the elements have been scrolled into view. In the code below, we are using the distance a user has scrolled, the height of the window, and the element's offset from the top to calculate this. For further explanation, you can look at this question on Stackoverflow. We then use the scroll event and this function to add the class fadeInLeft to our elements.

Once again, that's all there is to it! All we need is a simple scrolling function to add our classes to the text blocks to create slick scroll animations. And, Animate.css does the rest. Here's our updated pen with the static and scroll animations:

Now let's turn to animations triggered by a click event.

Click Animations

To illustrate click animation with Animate.css we'll create a contact form. When the form is submitted, we'll use some jQuery to check it for empty inputs. If any of these are empty, we'll give them a red border and shake them to let the user know they missed something. Here's the basic markup for form:

Now many of you might be thinking, 'Wow, this painfully easy! All we have to do is add the classes we want when the button is clicked just like with the scroll animations!' However, in this situation there's a little bit of a caveat. With the scroll animations, we only needed them to run once after they had been scrolled into view. They don't keep fading in every time they're scrolled in. But, in our present situation, we want our inputs to shake every time the button is clicked. Here's an example of this problem:

Notice how the inputs don't shake after the first time. This is because they already have the classes animated and shake. So, we need some way to remove these classes after the animation ends. Then, we'll be able to re-add them later. Once again, Animate.css to the rescue! With the following JavaScript, we can check for the end of our animation and then do something about it.

*Note: The .one() method is essentially identical to the .on() method. You can read more about its nuances here.*

Now that we have this nifty jQuery method, let's go through the logic of what we need to happen.

  1. We need to check for empty inputs when the submit button is clicked.
  2. If an input is empty, we need to give it the classes .animated, .shake, and .form-error (this last one is for styling the input border).
  3. Finally, we need to remove these classes when the animation ends.

To accomplish these three goals, we'll create an 'on click' function with if statements to validate each form element. We'll also use our event listener, so the animations can be run over and over again. Putting it all together, our JavaScript will look something like this:

Bear in mind that the class .form-error just creates red borders around the input boxes. You can check out the live demo to see this in action. And, that's about it for click animations with Animate.css. Obviously, we've only scratched the surface of what you can do with JavaScript and these awesome animations, but I'm sure your head is already buzzing with ideas for upcoming projects. Here's an updated codepen showing what we have so far:

As a final bonus section, I'd like to take a quick look at some really funky animations that Animate.css has in its library. I'm honestly not sure if these could ever be used in a production site, but they're kind of fun to tinker with!

Funky Animations

If you navigate to the official Animate.css site, you'll notice there's a category of animations labeled 'special.' There are several effects in this category, but right now, I want to take a look at hinge in particular. You can use this animation just like any other one in the Animate.css library, but it's definitely unique. It's probably easier to show rather than explain what exactly it does. So, check out the GIF below:

In the example above, all I've done is add an animation for each time the text is clicked - just like before. It's also worth noting that using this animation takes some extra code to use properly. This is because the hinge effect uses its parent container as a reference for the swinging motion. Thus, if you leave the element you want to animate 'out in space,' part of the animation may happen off screen. Here's the last bit of code.

*Note: This code is pretty much identical to our other 'on click' animations.*

Number Counter Clicker Online

Here's a link to the finished project with all the bell and whistles:

Counteranimated number counter for your website builder

Conclusion

And, that about wraps it up for our tour Animate.css! Let's recap what we've gone over:

  1. First, we learned how to get up and running with Animate.css
  2. Then, we took an in-depth look at three different types of animations: static, scroll, and click
  3. Finally, we experimented with some of this library's funkier (and significantly less useful) effects - just for giggles

I hope you enjoyed this guide (my first!) and are beginning to see all the clever ways this library can be implemented in web design. If you have any questions or comments please feel free to leave me a note in the comments.

For

Read next..

Putting a hit counter on a web page helps you track how many people visit it. There are several ways to go about putting a counter on your page, either by adding a pre-built one or creating your own.

Tip

We highly recommend using the Google's Analytics service over any web page counter, as it gives you a lot more valuable information.

Adding a pre-built counter

If you prefer to add a pre-built counter to your web page, here are a few ways to do so.

Wrongs cuore di eleganzawrenegade stables for sale. WRNGS Cuore di Eleganza Being the last foal out of Classy Heart, Cuore grew up an orphan after the death of her dam, bottle-fed and carefully watched through her early years. She is the only Wrenegade-owned horse to be kept on Jalal's main property, to keep her closer to the family and easier to watch out for, as DImitri had become incredibly.

  • Check with the web host for your web page. Often the company hosting your web page offer free solutions and provide instructions on how to add the counter code to your web page.
  • You can get a pre-built counter from websites that offer free counters, and add it to your web page with only a few lines of code. We recommend the following sites for free counters.

Example of the free-counter-plus counter

Note

A counter like the one used above increases in count if you or any visitor refreshes their browser.

Create a counter

To create a counter, you need to create a Perl, PHP, or another script. Then, you need to either refer to that script through a server-side include or another method. We recommend you already know or learn Perl or PHP programming to create the counter script.

The code for creating a counter can vary, depending on the programming language used and the type of counter you want to add to your web page. Below are some web pages that offer sample counter script code, which you can use as a guide to creating a counter.

Counter Animated Number Counter For Your Website Site

Note

Counteranimated Number Counter For Your Website Site

We have not tested the sample counter scripts provided on these web pages, so we cannot guarantee they're bug-free.

Counter Animated Number Counter For Your Website Free

Additional information

  • See the traffic and hit for further information about these terms and related links.