{"id":89629,"date":"2012-07-31T10:00:25","date_gmt":"2012-07-31T14:00:25","guid":{"rendered":"http:\/\/wpmu.org\/?p=89629"},"modified":"2013-04-27T20:08:06","modified_gmt":"2013-04-28T00:08:06","slug":"wordpress-animation","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/wordpress-animation\/","title":{"rendered":"3 WordPress Animation Tricks with animate.css"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-medium wp-image-90477\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/07\/animate-wordpress-title-300x204.jpg\" alt=\"Animate WordPress-image of WordPress logo over title sequence storyboard\" width=\"300\" height=\"204\" \/>Have you ever wanted WordPress animations to spice up your website with some subtle effects? The freely-available <a href=\"https:\/\/animate.style\/\" target=\"_blank\">animate.css toolset<\/a> can help you make it happen in most decent browsers&#8211;and won\u2019t break things for older browsers, either. Check out the general animate.css demo, and then learn how to use it to add some hop, skip, and jump to WordPress!<\/p>\n<h2 style=\"clear: right;\">Essential first step for WordPress animate.css<\/h2>\n<p>I\u2019ll show you different ways to animate your web content. No matter which ways you use, the first step is the same: include the \u201canimate.css\u201d file in your site\u2019s \u201chead\u201d area.<\/p>\n<h3>Download the animate.css files and unzip<\/h3>\n<p>First, visit the <a title=\"animate.css at github\" href=\"https:\/\/github.com\/daneden\/animate.css\" target=\"_blank\">animate.css github page<\/a>. For now, just click the \u201cZIP\u201d button to download the complete repository. Later, you\u2019ll see how to create a custom build of the CSS to keep your included file size as small as possible.<\/p>\n<p>Unzip the downloaded file and have a look inside. The complete set of animations is included in the \u201canimate.css file,\u201d but we\u2019re interested in the \u201canimate.min.css\u201d file. It has been minified to cut down on file size.<\/p>\n<h3>Copy animate.min.css file to your WordPress theme folder<\/h3>\n<p>For this tutorial, I\u2019m using the Twenty Eleven theme. I made a folder named \u201ccss\u201d inside the \u201ctwentyeleven\u201d folder, and copied the \u201canimate.min.css\u201d file there.<\/p>\n<h3>Tell WordPress to include animate.min.css in your page head<\/h3>\n<p>You might think it\u2019s okay to just put a style link directly in your head area, usually found in header.php for WordPress themes. That\u2019s a big no-no. Instead, you\u2019ll use WordPress\u2019 \u201cenqueue_style\u201d function. See the <a href=\"http:\/\/codex.wordpress.org\/Function_Reference\/wp_enqueue_style\" target=\"_blank\">enqueue_style Codex page<\/a> if you need more information on how the function works.<\/p>\n<p>Open your theme\u2019s \u201cfunctions.php\u201d file, scroll to the end, insert the following code, and save the file.<\/p>\n<pre>function paukai_2011_styles() {\r\n    wp_register_style( 'animate-css',\r\n        get_template_directory_uri() . '\/css\/animate.min.css',\r\n        array(),\r\n        '20120725',\r\n        'screen' );\r\n    wp_enqueue_style( 'animate-css' );\r\n}\r\nadd_action('wp_enqueue_scripts', 'paukai_2011_styles');<\/pre>\n<p>Adding the stylesheet for the \u201cwp_enqueue_scripts\u201d hook will add it for every front side page of your site.<\/p>\n\n<h2>Animation Method 1: Manually add classes to elements in your content using the HTML editor<\/h2>\n<p>For this first example, just make a post with 3 paragraphs, and style the 2nd paragraph as a blockquote. Then, enter the HTML editor and add two classes to the blockquote element:<\/p>\n<ul>\n<li>\u201canimated\u201d<\/li>\n<li>\u201cwobble\u201d<\/li>\n<\/ul>\n<p>Your blockquote element should look like this:<\/p>\n<pre>&lt;blockquote class=\"animated wobble\"&gt;Your content here&lt;\/blockquote&gt;<\/pre>\n<p>The \u201canimated\u201d class is required for any element you want to animate. The \u201cwobble\u201d class is but one of many different keyframe effects you can apply. See the animate.css homepage for a complete list of effects.<\/p>\n<h3>The next step<\/h3>\n<p>My friend&#8211;there is no next step! Save your page and view it to see that blockquote wobble.<\/p>\n<h2>Customizing animations<\/h2>\n<h3>Looping the animation<\/h3>\n<p>The wobble is pretty neat, but it starts as soon as the page loads, and might be easy to miss. Here\u2019s how to tell the animation to run a certain number of times. For the example, you\u2019ll make it loop infinitely.<\/p>\n<p>Back in the HTML editor for your post, add the following style declarations to the blockquote element:<\/p>\n<pre>-webkit-animation-iteration-count: infinite;\r\n-moz-animation-iteration-count: infinite;\r\n-ms-animation-iteration-count: infinite;\r\n-o-animation-iteration-count: infinite;<\/pre>\n<p>Your blockquote element should look like this:<\/p>\n<pre>&lt;blockquote class=\"animated wobble\" style=\"-webkit-animation-iteration-count: infinite; -moz-animation-iteration-count: infinite; -ms-animation-iteration-count: infinite; -o-animation-iteration-count: infinite;\"&gt;Your content here&lt;\/blockquote&gt;<\/pre>\n<p>I know&#8211;that is getting completely out of hand. I\u2019ll address that in a moment! For now, just know that you need all 4 of those declarations for these CSS3 effects to work in different browsers.<\/p>\n<p>Save the page and test it out.<\/p>\n<h3>Delaying the animation start<\/h3>\n<p>Your blockquote should be wobbling back and forth, again and again. Pretty cool! It can also get annoying, but I\u2019ll talk about that in a bit. Right now, your blockquote wobbles as soon as the page finishes loading. Here\u2019s how to make it wait 5 seconds before wobbling.<\/p>\n<h4>Adding your own control classes<\/h4>\n<p>Instead of littering your page HTML with 4 more declarations to delay animation start, you\u2019ll add a CSS class to your stylesheet, then apply that class to your HTML. Open your theme\u2019s style.css file, scroll to the end, and add the following class:<\/p>\n<pre>.delay3 {\r\n    -webkit-animation-delay: 5s;\r\n      -moz-animation-delay: 5s;\r\n        -ms-animation-delay: 5s;\r\n          -o-animation-delay: 5s;\r\n}<\/pre>\n<p>Save the file. Then, edit your post again and add the \u201cdelay3\u201d class to your blockquote element. The class attribute should now read \u201canimated wobble delay3\u201d. Save your post and go have a look. The wobbling should wait 5 seconds before it starts.<\/p>\n<p>Adding the \u201cdelay3\u201d class enabled you to keep your HTML cleaner, and you can use it again on other animated elements where a 5 second delay is needed. To clean up your HTML more, move the looping declarations to a class. In your style.css file, add the following class:<\/p>\n<pre>.loopinf {\r\n    -webkit-animation-iteration-count: infinite;\r\n      -moz-animation-iteration-count: infinite;\r\n        -ms-animation-iteration-count: infinite;\r\n          -o-animation-iteration-count: infinite;\r\n}<\/pre>\n<p>Save the file, edit your post, and add the \u201cloopinf\u201d class to your blockquote. Its class attribute will now read \u201canimated wobble delay3 loopinf\u201d. You should remove the entire \u201cstyle\u201d attribute you added earlier for looping the animation&#8211;your new \u201cloopinf\u201d class takes care of those declarations. Your blockquote element should now read:<\/p>\n<pre>&lt;blockquote class=\"animated wobble delay3 loopinf\"&gt;Your text here&lt;\/blockquote&gt;<\/pre>\n<p>Save the post and test. While you shouldn\u2019t see any different behavior, your HTML is much cleaner.<\/p>\n<h3>Making the animation last longer<\/h3>\n<p>Now you can make the wobble effect occur over a longer period of time&#8211;say 5 seconds. (The default for most effects is 1 second.) This should make the effect look slower, as you stretch the same number of movements (keyframes) over a longer time.<\/p>\n<p>Add the following class to your style.css file and save it:<\/p>\n<pre>.duration5 {\r\n    -webkit-animation-duration: 5s !important;\r\n      -moz-animation-duration: 5s !important;\r\n        -ms-animation-duration: 5s !important;\r\n          -o-animation-duration: 5s !important;\r\n}<\/pre>\n<p>If you leave out <code>!important<\/code> the default duration will be used instead of your new 5 seconds. Edit your post, add the \u201cduration5\u201d class to your blockquote, save and test.<\/p>\n<h2>Animate elements on hover<\/h2>\n<p>I don\u2019t know about you, but I think having an element animate like this, all by itself, is mostly annoying and useless. I\u2019d rather animate elements in response to some user action. The simplest example is to animate the element when visitors move their mouse over it.<\/p>\n<h4>A quick CSS reminder<\/h4>\n<p>To change the styling of an element when the mouse moves over that element, we need to put the additional styles inside a ruleset targeting the pseudo-class \u201c:hover,\u201d like this:<\/p>\n<pre>myselector:hover {\r\n    property: value;\r\n}<\/pre>\n<p>For the animate.css classes, the rules that make elements actually animate are specified in the \u201canimated\u201d class. That selector is defined in the \u201canimate.min.css\u201d file, which you really shouldn\u2019t alter, since the developer might make updates.<\/p>\n<p>You need to look at the \u201canimated\u201d rule in \u201canimate.css,\u201d discover what rules make an element animate, and copy them to the \u201cmyselector:hover\u201d rule. Then you can remove the \u201canimated\u201d class from your HTML element, since your new \u201chover\u201d rule includes what you need.<\/p>\n<h4>Declarations from \u201canimated\u201d rule<\/h4>\n<pre>.animated {\r\n    -webkit-animation-duration: 1s;\r\n      -moz-animation-duration: 1s;\r\n        -o-animation-duration: 1s;\r\n          animation-duration: 1s;\r\n    -webkit-animation-fill-mode: both;\r\n      -moz-animation-fill-mode: both;\r\n        -o-animation-fill-mode: both;\r\n          animation-fill-mode: both;\r\n}<\/pre>\n<p>It looks like the \u201canimation-duration\u201d and \u201cfill-mode\u201d are the important declarations to make animation begin.<\/p>\n<h4>Create your element\u2019s :hover rule<\/h4>\n<p>In your style.css file, add the following class:<\/p>\n<pre>.pekanimate:hover {\r\n    -webkit-animation-duration: 1s;\r\n      -moz-animation-duration: 1s;\r\n       -o-animation-duration: 1s;\r\n        animation-duration: 1s;\r\n    -webkit-animation-fill-mode: both;\r\n      -moz-animation-fill-mode: both;\r\n        -o-animation-fill-mode: both;\r\n        animation-fill-mode: both;\r\n}<\/pre>\n<h4>Remove \u201canimated\u201d class from your HTML<\/h4>\n<p>Back in the HTML of your post, simplify the \u201cblockquote\u201d element. Remove the \u201canimated\u201d class&#8211;that\u2019s taken care of by your \u201cpekanimate:hover\u201d class. You do need to leave the specific animation type class, such as \u201cwobble.\u201d So, set your blockquote to the following, save, and test by hovering over the blockquote on the published page.<\/p>\n<pre>&lt;blockquote class=\"pekanimate wobble\"&gt;Your content here&lt;\/blockquote&gt;<\/pre>\n<p>Your blockquote should wobble one time when you hover over it. Pretty cool, eh?! It will not continue to wobble if you move your mouse off and back over it. If you want to do that, you need to allow the animation to loop infinitely by adding the following to your \u201cpekanimate:hover\u201d class:<\/p>\n<pre>-webkit-animation-iteration-count: infinite;\r\n  -moz-animation-iteration-count: infinite;\r\n    -ms-animation-iteration-count: infinite;\r\n      -o-animation-iteration-count: infinite;<\/pre>\n\n<h2>Animation Method 2: Adding classes to elements in your theme templates<\/h2>\n<p>We just learned a lot while implementing method 1. Requiring HTML edits to manually add classes, though, is not practical in a lot of situations.<\/p>\n<p>Perhaps you have content authors uncomfortable editing HTML, but you need them to add an animated call to action (CTA) on some posts. You can make that easy on your authors by building the animated element into your theme templates.<\/p>\n<h3>Adding an animated element to a template.<\/h3>\n<p>Let\u2019s say you want an animated element after your title and before the content on individual blog posts.<\/p>\n<p>In the \u201cTwenty Eleven\u201d theme, the title and content for single posts are controlled by the file \u201ccontent-single.php,\u201d so open that file. The title and optional meta information are wrapped in a \u201cheader\u201d element. You&#8217;ll add your CTA as the last element inside the \u201cheader\u201d element.<\/p>\n<p>You\u2019ll simply add a \u201cdiv\u201d element with classes \u201cpekanimate\u201d and \u201cwobble.\u201d For now, just fill it with some nonsense text. Here is the header element after your changes:<\/p>\n<pre>&lt;header&gt;\r\n    &lt;h1&gt;&lt;?php the_title(); ?&gt;&lt;\/h1&gt;\r\n    &lt;?php if ( 'post' == get_post_type() ) : ?&gt;\r\n    &lt;div&gt;\r\n        &lt;?php twentyeleven_posted_on(); ?&gt;\r\n    &lt;\/div&gt;&lt;!-- .entry-meta --&gt;\r\n    &lt;?php endif; ?&gt;\r\n    &lt;div class=\"pekanimate wobble\"&gt;\r\n        Here is my call to action text for the demonstration.\r\n    &lt;\/div&gt;\r\n&lt;\/header&gt;&lt;!-- .entry-header --&gt;<\/pre>\n<p>Save those changes to \u201ccontent-single.php\u201d and go view any single blog post. When you mouse over the CTA, it should begin to wobble.<\/p>\n<p>Now make the CTA stand out a bit. In your style.css file, create a new class&#8211;\u201cpekcta\u201d&#8211;like the following:<\/p>\n<pre>.pekcta{\r\n    padding:12px;\r\n    background-color:#ddd;\r\n    border:4px solid #fff;\r\n    color:#000;\r\n    font-weight:bold;\r\n    font-size:1.2em;\r\n}<\/pre>\n<p>Then, add the \u201cpekcta\u201d class to your CTA element in the \u201ccontent-single.php\u201d file.<\/p>\n<pre>&lt;div class=\"pekanimate wobble pekcta\"&gt;\r\n    Here is my call to action text for the demonstration.\r\n&lt;\/div&gt;<\/pre>\n<p>Save your changed files and reload the single blog post on your site. I think you\u2019ll agree that is a bit better than just plain text.<\/p>\n<h3>Making your animated element easy to edit<\/h3>\n<p>Now you have an animated element requiring no manual HTML editing. However, you need to be able to edit the content easily, and optionally choose to have the CTA not show at all. You\u2019ll do that by adding a few custom meta boxes to the post editing page, then adding logic to the \u201ccontent-single.php\u201d file.<\/p>\n<h4>Adding the \u201cMore Fields\u201d custom meta plugin<\/h4>\n<p>There are many ways to use custom field values in your posts. Indeed, you could just use the built-in custom fields panel and give your authors instructions. However, you can make the edit screens more professional and easier to use by adding custom meta boxes to the edit screen. You could code that manually, or use one of many good plugins available. I\u2019m going to show you how to use the \u201cMore Fields\u201d plugin.<\/p>\n<p dir=\"ltr\"><strong>Install and setup &#8220;More Fields&#8221;<\/strong><\/p>\n<p>In your dashboard, go to \u201cPlugins &gt; Add New,\u201d search for \u201cmore fields,\u201d then install and activate the \u201cMore Fields\u201d plugin.<\/p>\n<h4>Setup new fields for edit screens<\/h4>\n<ol>\n<li>Go to \u201cSettings &gt; More Fields,\u201d and click \u201cAdd new input box\u201d on the \u201cMore Fields\u201d screen.<\/li>\n<li>Enter \u201cCall to Action\u201d as the title of the box.<\/li>\n<li>Check only \u201cPosts\u201d for the \u201cUsed with post types\u201d option, since we\u2019re only gearing single post templates to make use of the CTA.<\/li>\n<li>Click \u201cSave.\u201d<\/li>\n<li>After saving, the \u201cMore Fields\u201d screen lists the new box, which you can now add fields to.<\/li>\n<li>Click \u201cEdit\u201d in the \u201cActions\u201d column for your \u201cCall to Action\u201d box.<\/li>\n<li>Click \u201cAdd new field\u201d in the \u201cList of fields\u201d (which is currently an empty list.)<\/li>\n<li>Enter \u201cCTA Content\u201d as the field title.<\/li>\n<li>Enter \u201cpek_cta_content\u201d as the custom field key.<\/li>\n<li>Enter the following as the caption:\u201cOptionally enter call to action content, including an HTML link, to show an animated call to action under your post title.\u201d<\/li>\n<li>Choose \u201cWYSIWYG\u201d as the field type.<\/li>\n<li>Click \u201cSave.\u201d<\/li>\n<\/ol>\n<h4>Check out the new edit screen<\/h4>\n<p><a rel=\"lightbox[89629]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/07\/animate-wordpress-cta-box.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-medium wp-image-90472\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/07\/animate-wordpress-cta-box-300x162.png\" alt=\"Animate WordPress-Screenshot of call to action box on edit screen\" width=\"300\" height=\"162\" \/><\/a>Now edit a post where you want to use the CTA. Scroll down, and you\u2019ll find the \u201cCall to Action\u201d box you just made.<\/p>\n<p dir=\"ltr\"><strong>Note:<\/strong> if your main content editor is on the \u201cHTML\u201d tab, the Call to Action box WYSIWYG editor toolbar will not appear. Simply choose the \u201cVisual\u201d tab in the main content editor and refresh your page.<\/p>\n<p>Enter your CTA message in the \u201cCTA Content\u201d field. You probably should create a link in the text, since this is a call to action. After all&#8211;your visitors need an action to perform! Save your post.<\/p>\n<h4>Rig your template for the new custom field<\/h4>\n<p>Now that you have an easy-to-use field for entering call to action content, you need to alter your template file to make use of the field. You\u2019ll be replacing the new \u201cpekcta\u201d div we made earlier.<\/p>\n<p>Replace the entire \u201cpekcta\u201d div in your \u201ccontent-single.php\u201d file with the following:<\/p>\n<pre>&lt;?php\r\n\/\/ retrieve cta custom field value if it exists\r\n$cta_content = get_post_meta( get_the_ID(), 'pek_cta_content', true );\r\nif( $cta_content ) {\r\n    \/\/ we have content we want to display, so let's build our cta element\r\n?&gt;\r\n&lt;div&gt;\r\n    &lt;?php echo $cta_content; ?&gt;\r\n&lt;\/div&gt;\r\n&lt;?php\r\n} \/\/ end if\r\n?&gt;<\/pre>\n<p>Save the file and go reload the blog post that you added CTA text to. Great! You now have control over the CTA without editing any HTML!<\/p>\n<h2>Animation Method 3: Adding classes dynamically to target elements using jQuery<\/h2>\n<p>Method 2 showed a practical way to implement animated elements. Now I\u2019ll show you how to animate in a more interactive way by starting and stopping animations of one element (a slide) based on actions your visitor takes with another element (a link.)<\/p>\n<h3>In-Content slider<\/h3>\n<p>You\u2019re going to give authors the option of creating a slider, right from the Edit Post screen. I\u2019m taking an example from the animate.css author\u2019s site and adapting \u00a0it to WordPress.<\/p>\n<h4>Add a box to edit screens for holding slider fields<\/h4>\n<ol>\n<li>Go to \u201cSettings &gt; More Fields,\u201d and click \u201cAdd new input box\u201d on the \u201cMore Fields\u201d screen.<\/li>\n<li>Enter \u201cPost Slider\u201d as the title of the box.<\/li>\n<li>Check only \u201cPosts\u201d for the \u201cUsed with post types\u201d option.<\/li>\n<li>Click \u201cSave.\u201d<\/li>\n<li>After saving, the \u201cMore Fields\u201d screen lists the new box, which you can now add fields to.<\/li>\n<li>Click \u201cEdit\u201d in the \u201cActions\u201d column for your \u201cPost Slider\u201d box.<\/li>\n<li>Click \u201cAdd new field\u201d in the \u201cList of fields\u201d (which is currently an empty list.)<\/li>\n<li>Enter \u201cSlider 1 Content\u201d as the field title.<\/li>\n<li>Enter \u201cpek_slide1_content\u201d as the custom field key.<\/li>\n<li>Enter the following as the caption:\u201cEnter content for slide 1 here.\u201d<\/li>\n<li>Choose \u201cWYSIWYG\u201d as the field type.<\/li>\n<li>Click \u201cSave.\u201d<\/li>\n<li>Add new fields for as many sliders as you want to allow. I recommend at least 3 and no more than 6. Be sure to change the name of the field title and custom field key to reflect the slider number. e.g., \u201cSlider 2 Content\u201d and \u201cpek_slide2_content,\u201d etc.<\/li>\n<\/ol>\n<h4>Ye Olde on\/off switch<\/h4>\n<p>After adding the fields for numerous sliders, you\u2019ll add one more field to allow the slider to be turned on or off.<\/p>\n<ol>\n<li>Add a new field with the title \u201cActivate Slider.\u201d<\/li>\n<li>Use \u201cpek_slider_active\u201d as the custom field key.<\/li>\n<li>Enter something like the following as the caption:\u201cCheck this box to make your sliders appear for this post.\u201d<\/li>\n<li>Choose \u201cCheckbox\u201d as the field type.<\/li>\n<li>Click \u201cSave.\u201d<\/li>\n<\/ol>\n<h4>Add test sliders to a post<\/h4>\n<p><a rel=\"lightbox[89629]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/07\/animate-wordpress-slider-field.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-medium wp-image-90473\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/07\/animate-wordpress-slider-field-300x180.png\" alt=\"Animate WordPress-screenshot of slider entry field on edit screen\" width=\"300\" height=\"180\" \/><\/a>When you\u2019re finished adding fields to your slider box, edit a post and add some content to at least 3 of the sliders, making sure to put a check in the \u201cActivate Slider\u201d box.<\/p>\n<h4>Rig your template for the new slider fields<\/h4>\n<p><strong><strong>In the template file \u201ccontent-single.php,\u201d you need to:<\/strong><\/strong><\/p>\n<ol>\n<li>Check if the \u201cActivate Slider\u201d checkbox is on. If it is, proceed.<\/li>\n<li>Add a \u201cul\u201d element to contain all our slides.<\/li>\n<li>Check for each individual slider.<\/li>\n<li>Create the &lt;li&gt; slider with appropriate classes, then dump the slider contents in there, properly escaped.<\/li>\n<li>Add an activation button for the slider.<\/li>\n<li>When all slides have been checked \/ added, close the \u201cul\u201d element that contains all slides.<\/li>\n<li>Add the slider buttons HTML.<\/li>\n<\/ol>\n<h4>Modified content-single.php file<\/h4>\n<p><a href=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/07\/content-single.zip\" target=\"_blank\">Download my modified version of the Twenty Eleven theme&#8217;s &#8220;content-single.php&#8221; file<\/a>. It&#8217;s well-commented, so you can understand what&#8217;s going on.<\/p>\n<p>After saving changes to your template file, view the sample post you made with slider content. After the post\u2019s normal page content, you should see an unordered list containing an item for each of your slides, followed by a line of linked text items like \u201cSlider 1,\u201d \u201cSlider 2,\u201d etc.<\/p>\n<h3>Additional CSS for your sliders<\/h3>\n<p>Open your style.css file, scroll to the bottom, and add some new rules you need for the sliders to function properly.<\/p>\n<h4>First, some styles for the slider container: the \u201cul.slides\u201d<\/h4>\n<pre>.slides {\r\n    -webkit-animation-delay: .5s;\r\n      -moz-animation-delay: .5s;\r\n        animation-delay: .5s;\r\n    -webkit-animation-fill-mode: both;\r\n      -moz-animation-fill-mode: both;\r\n        animation-fill-mode: both;\r\n    -webkit-animation-name: fadeInUp;\r\n      -moz-animation-name: fadeInUp;\r\n        animation-name: fadeInUp;\r\n    width: 100%;\r\n    height: 400px;\r\n    position: relative;\r\n    margin: 1.5em 0;\r\n}<\/pre>\n<h4>Second, some styles for the slides themeselves: the \u201c.slides li\u201d<\/h4>\n<pre>.slides li {\r\n    position: absolute;\r\n    top: 0;\r\n    left: 0;\r\n    display: block;\r\n    width: 96%;\r\n    padding: 2%;\r\n    list-style: none;\r\n    background: #fff;\r\n    margin: 0 auto;\r\n    border-radius: 5px;\r\n    box-shadow: 0 0 2px 1px rgba(0,0,0,.1);\r\n    -webkit-backface-visibility: hidden;\r\n      -moz-backface-visibility: hidden;\r\n        -ms-backface-visibility: hidden;\r\n          backface-visibility: hidden;\r\n    -webkit-animation-duration: 1s\r\n      -moz-animation-duration: 1s;\r\n        -ms-animation-duration: 1s;\r\n          animation-duration: 1s;\r\n    -webkit-animation-timing-function: ease\r\n      -moz-animation-timing-function: ease;\r\n        -ms-animation-timing-function: ease;\r\n          animation-timing-function: ease;\r\n    -webkit-animation-fill-mode: both;\r\n      -moz-animation-fill-mode: both;\r\n        -ms-animation-fill-mode: both;\r\n          animation-fill-mode: both;\r\n    opacity: 0;\r\n    z-index: 1;\r\n}<\/pre>\n<h4>Third, styles for the inactive sliders.<\/h4>\n<p>When a slider needs to change from being visible to the user to invisible, it will be classed as \u201cinactive.\u201d<\/p>\n<pre>.slides .inactive {\r\n    -webkit-animation-fill-mode: backwards;\r\n      -moz-animation-fill-mode: backwards;\r\n        -ms-animation-fill-mode: backwards;\r\n          animation-fill-mode: backwards;\r\n    -webkit-animation-name: fadeOutRight;\r\n      -moz-animation-name: fadeOutRight;\r\n        -ms-animation-name: fadeOutRight;\r\n          animation-name: fadeOutRight;\r\n}<\/pre>\n<h4>Fourth, styles for the active sliders.<\/h4>\n<p>When a slider needs to become visible, it will be classed as \u201cactive.\u201d<\/p>\n<pre>.slides .active {\r\n    -webkit-animation-name: fadeInLeft;\r\n      -moz-animation-name: fadeInLeft;\r\n        -ms-animation-name: fadeInLeft;\r\n          animation-name: fadeInLeft;\r\n    -webkit-animation-delay: .5s;\r\n      -moz-animation-delay: .5s;\r\n        -ms-animation-delay: .5s;\r\n          animation-delay: .5s;\r\n    opacity: 1 !important;\r\n    z-index: 5;\r\n}<\/pre>\n<h3>Additional JavaScript for your sliders<\/h3>\n<p>Visitors choose which slide to see by clicking the links underneath the slider display area. When they click, the JavaScript function \u201cslide\u201d is called, passing in the number of the slide which the link should activate.<\/p>\n<p>For this to work, you need to make a small JavaScript file available to your page in the \u201chead.\u201d The file contains the JavaScript function \u201cslide.\u201d<\/p>\n<ol>\n<li>In your theme folder, make a \u201cjs\u201d folder, if it doesn\u2019t already exist.<\/li>\n<li>In the \u201cjs\u201d folder, create a new file named \u201canimate-css.js\u201d.<\/li>\n<li>Add the following to the file and save it:<\/li>\n<\/ol>\n<pre>function slide(n) {\r\n    jQuery('.active').removeClass('active').addClass('inactive');\r\n    jQuery('.slide' + n).addClass('active').removeClass('inactive');\r\n}<\/pre>\n<h4>Load the new JavaScript<\/h4>\n<p>Now you need to load that JavaScript for your pages. Go back to your theme\u2019s \u201cfunctions.php\u201d file and scroll to the bottom. Previously, you enqueued some CSS here. Now you\u2019ll enqueue the new JavaScript file.<\/p>\n<p>Add the following to the end of your \u201cpaukai_2011_styles\u201d function and save the file.<\/p>\n<pre>\/\/ add new JS\r\nwp_enqueue_script(\r\n    'animate-css-script',\r\n    get_template_directory_uri() . '\/js\/animate-css.js',\r\n    array('jquery')\r\n);<\/pre>\n<h3>Testing the new slider<\/h3>\n<p>That should do it! Refresh the post you added slider items too, and click the different slide links to watch your new slider in action.<\/p>\n<h2>Adding only what you need<\/h2>\n<p><a rel=\"lightbox[89629]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/07\/animate-wordpress-custom-build.png\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-medium wp-image-90475\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/07\/animate-wordpress-custom-build-300x253.png\" alt=\"Animate WordPress-screenshot of custom CSS build selection screen\" width=\"300\" height=\"253\" \/><\/a>Throughout this tutorial, you\u2019ve been using a fully-loaded animate.css file. While minimized into animate-min.css, it still clocks in at 47K.<\/p>\n<p>The entire tutorial only makes use of animation effects for \u201cwobble,\u201d \u201cfadeInLeft,\u201d and \u201cfadeOutRight.\u201d You can build a custom css file including only the animation effects you really intend to use, thereby cutting down your file size page load time.<\/p>\n<h4>Build a customized animate.css<\/h4>\n<p>The animation effects are listed on the site under different classifications, such as \u201cAttention seekers,\u201d \u201cFlippers,\u201d and so forth. Click \u201cuncheck all\u201d for each of the classifications. Then just check on the three effects we\u2019re actually using.<\/p>\n<ul>\n<li>\u201cwobble\u201d from \u201cAttention seekers.\u201d<\/li>\n<li>\u201cfadeInLeft\u201d from \u201cFading Entrances.\u201d<\/li>\n<li>\u201cfadeOutRight\u201d from \u201cFading Exits.\u201d<\/li>\n<\/ul>\n<p>Click \u201cBuild it\u201d and download the resulting css. For the effects we use in this tutorial, the custom build file is only 5K&#8211;and it isn\u2019t even minified!<\/p>\n<p>Minifying the file at <a href=\"http:\/\/www.minifycss.com\/css-compressor\/\" target=\"_blank\">http:\/\/www.minifycss.com\/css-compressor\/<\/a> with the \u201cHigh\u201d compression level takes that down to 1.9K. NOTE: If you do this, you are required to keep the comment block that includes the license at the top of the css file. The compressor will remove such comments, but you need to keep the license text, one way or the other.<\/p>\n<p>Give your custom build file whatever name you want. Copy it to your theme\u2019s \u201ccss\u201d folder. Finally, visit your \u201cfunctions.php\u201d file to edit the name of the css file you want WordPress to enqueue.<\/p>\n<h2>Preaching restraint<\/h2>\n<h3>Good heavens, don\u2019t let this turn out like the old HTML &lt;blink&gt; tag!<\/h3>\n<p>Animation draws attention to some elements. If you overuse animation by adding it to too many elements, you lose the benefit of drawing attention to anything specific. Consider adding animation to only 1 or 2 key elements, like calls to action. (You should only have 1 call to action on your page anyway, but that\u2019s not what this article is about.)<\/p>\n<h3>A note about accessibility<\/h3>\n<p>Animation should never be required in order to understand the content of your page. Remember that people using older browsers may not see any animation. Also, anyone using a screen reader to digest your site will not know of any animation you use. I\u2019ve never heard a screen reader say \u201cthe following paragraph is wobbling!\u201d<\/p>\n<h3>What do you think?<\/h3>\n<p>I hope you now understand the mechanics of adding animate.css effects to your WordPress site. Do you have any questions I didn\u2019t answer well? Are there other ways you\u2019d like to use animate.css that I didn\u2019t cover? Let me know what you think in the comments. I\u2019d love to help you further.<\/p>\n<h2>Credits<\/h2>\n<ul>\n<li>Title sequence sketch\u00a0photo by:\u00a0<a href=\"http:\/\/flickr.com\/23643241@N05\/3214864072\" rel=\"noopener\" target=\"_blank\">david.torcivia<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Easily add subtle animations to elements in your WordPress site using animate.css.<\/p>\n","protected":false},"author":97717,"featured_media":90477,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[263],"tags":[1044],"tutorials_categories":[],"class_list":["post-89629","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-css"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/89629","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/97717"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=89629"}],"version-history":[{"count":2,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/89629\/revisions"}],"predecessor-version":[{"id":204625,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/89629\/revisions\/204625"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media\/90477"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=89629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=89629"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=89629"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=89629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}