We are wondering if it is possible to dynamically add a CSS class for animated every image element on the website (or every column) instead of doing it manually in each element. Is this possible through CSS pseudoclasses or adding a PHP function?
Thank you!
Candy
Hey Candy,
Thanks for your question, it would be possible but all elements don’t share the same animation classes and typically multiple classes are required, for example on a basic image element the top-to-bottom animation requires 3 classes. In my test this script will add this animation for all images in a image element:
function custom_animated_image() { ?>
<script>
(function($){
$('.avia-image-container').addClass('avia_animated_image avia_animate_when_almost_visible top-to-bottom');
})(jQuery);
</script>
<?php
}
add_action('wp_footer', 'custom_animated_image');
You can test this by adding this code to the end of your functions.php file in Appearance ▸ Editor
Best regards,
Mike
Thanks, Mike! That seemed to work! It seems a little slow / buggy though. You can see that working on 5 images on this page:
Are there any downsides to this approach in terms of performance or otherwise that you can think of?
Hi,
This script is running after the DOM, so you are giving on this end instead of using the element options when the page is built.
So this would be ok if after placing hundreds of images you realized that you wanted the animation, but I would not recommend it as an excuse to not select the option when the page was built the first time.
Perhaps using Custom Element Templates would be better so your elements already have your basic options defined.
Best regards,
Mike
Got it thanks for the clarification!
Hi,
Glad we were able to help, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.
Best regards,
Mike