Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1349570

    Hello,

    Is it possible, even if we need to use custom code, to animate each word in a text block element? Something similar to the following? https://dns.d.pr/lRPTJ1/lhcsEHcSqU

    It would be great if we can use this in multiple places by assigning a Custom ID Attribute or a Custom CSS Class.

    Many thanks.

    #1349600

    Hey sitesme,

    Yes it’s possible however you would need to write some js and CSS code.
    I have found something interesting that might help you with it: https://tobiasahlin.com/moving-letters/
    Hope it helps.

    Best regards,
    Nikko

    #1349631

    Hi @Nikko

    Thank you for this lead. Looks great.
    I can add the js and CSS code in WordPress through a Header plugin, this is not a problem, but I have no idea how to adapt this to Avia Layout.
    Could you please tell me how can I apply this animation code to Enfold? https://tobiasahlin.com/moving-letters/#3

    Thank you

    #1349686

    Hi,

    Thanks for the update. Did you try adding the ml3 class to the element which you want to animate?

    Best regards,
    Rikard

    #1349720

    Hi sitesme,

    On you child theme, create a folder and name it js, inside it create a file called moving-letters.js and inside the file paste this code:

    // Wrap every letter in a span
    var textWrapper = document.querySelector('.ml3');
    textWrapper.innerHTML = textWrapper.textContent.replace(/\S/g, "<span class='letter'>$&</span>");
    
    anime.timeline({loop: true})
      .add({
        targets: '.ml3 .letter',
        opacity: [0,1],
        easing: "easeInOutQuad",
        duration: 2250,
        delay: (el, i) => 150 * (i+1)
      }).add({
        targets: '.ml3',
        opacity: 0,
        duration: 1000,
        easing: "easeOutExpo",
        delay: 1000
      });

    Then in functions.php of your child theme, add this code:

    add_action( 'wp_enqueue_scripts', 'wp_animate_text', 100 );
    
    function wp_animate_text() {
       wp_enqueue_script( 'anime-js', 'https://cdnjs.cloudflare.com/ajax/libs/animejs/2.0.2/anime.min.js', '', '2.0.2', true);
       wp_enqueue_script( 'moving-letters-js', get_stylesheet_directory_uri().'/js/moving-letters.js', array('anime-js'), '1.0.0', true);
    }

    If you use a Special Heading, you can just directly add the class ml3 via Advanced (tab) > Developer Settings > Custom CSS Class.
    If you are using a Text Block then change it from Visual mode to Text mode then add it like this:
    <p class="ml3">Click here to add your own text</p>
    Hope this helps.

    Best regards,
    Nikko

    • This reply was modified 2 years, 6 months ago by Nikko.
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.