Skip to main content
kineticcreative123
Inspiring
November 21, 2018
Answered

Need SVG animation to load on scroll

  • November 21, 2018
  • 1 reply
  • 3641 views

Hey Everyone,

I have an animation I'm trying to get to load when scrolled to that portion of the page. I've dded some script and a class to my div using revealOnScroll. Would this be the correct script to use?

Here is a working link.

http://offers.premierinc.com/Scroll-Test_Scroll-Test.html

Thanks for any help!

    This topic has been closed for replies.
    Correct answer osgood_

    Logic says remove the below function from your EVO js file, which is right at the start of the file, then use the well documented script for checking if a container comes into the viewport in your page and insert the function you removed from the EVO js file were it says -

    INSERT THE ABOVE FUNCTION HERE

    (see below)

    See if that works.

    Remove the below from EVO js file:

    $(function(){

    $("#doughnutChart").drawDoughnutChart([

    { title: "Tokyo",         value : 120,  color: "#003b49" },

    { title: "San Francisco", value:  9,   color: "#0091b3" },

    { title: "New York",      value:  6,   color: "#8dc7d8" },

    { title: "London",        value : 120,   color: "#7a979f" },

    { title: "Berlin",        value : 40,   color: "#ffc627" }

    ]);

    });

    Insert the above function into the script below (which should go in your page inplace of the other one you currently have) to check when a container comes into viewport:

    <script>

    function isInView(elem)

    {

    var docViewTop = $(window).scrollTop();

    var docViewBottom = docViewTop + $(window).height() - 200;

    var elemTop = $(elem).offset().top;

    return ((elemTop <= docViewBottom) && (elemTop >= docViewTop));

    }

    $(window).scroll(function(){

    if (isInView($('#doughnutChart'))) {

    INSERT THE ABOVE FUNCTION HERE

    $(window).off('scroll');

    }

    })

    </script>

    1 reply

    osgood_Correct answer
    Legend
    November 22, 2018

    Logic says remove the below function from your EVO js file, which is right at the start of the file, then use the well documented script for checking if a container comes into the viewport in your page and insert the function you removed from the EVO js file were it says -

    INSERT THE ABOVE FUNCTION HERE

    (see below)

    See if that works.

    Remove the below from EVO js file:

    $(function(){

    $("#doughnutChart").drawDoughnutChart([

    { title: "Tokyo",         value : 120,  color: "#003b49" },

    { title: "San Francisco", value:  9,   color: "#0091b3" },

    { title: "New York",      value:  6,   color: "#8dc7d8" },

    { title: "London",        value : 120,   color: "#7a979f" },

    { title: "Berlin",        value : 40,   color: "#ffc627" }

    ]);

    });

    Insert the above function into the script below (which should go in your page inplace of the other one you currently have) to check when a container comes into viewport:

    <script>

    function isInView(elem)

    {

    var docViewTop = $(window).scrollTop();

    var docViewBottom = docViewTop + $(window).height() - 200;

    var elemTop = $(elem).offset().top;

    return ((elemTop <= docViewBottom) && (elemTop >= docViewTop));

    }

    $(window).scroll(function(){

    if (isInView($('#doughnutChart'))) {

    INSERT THE ABOVE FUNCTION HERE

    $(window).off('scroll');

    }

    })

    </script>

    kineticcreative123
    Inspiring
    November 26, 2018

    osgood!!! Excellent!! That did the trick. Saving this to my code snippet library!

    The animation is being placed as a code block on a landing page built in iON. I think you have heard me speak of this before. Before I ask them why this is happening would you have an idea of why the animation would be duplicating down the page?

    Check it out...

    click the red box "Actionable Business Intelligence Capabilities" and you will see the animation.

    Physician Enterprise Collaborative | Premier

    I'm also noticing that the text slightly moves when scaled. It has absolute positioning...

    Legend
    November 26, 2018

    kineticcreative123  wrote

    osgood!!! Excellent!! That did the trick. Saving this to my code snippet library!

    The animation is being placed as a code block on a landing page built in iON. I think you have heard me speak of this before. Before I ask them why this is happening would you have an idea of why the animation would be duplicating down the page?

    I do know but Im not quite sure how to prevent that happening. The $(window).off('scroll'); in the script should only allow the window scroll function to fire once but it doesnt seem to be working and consequently every time the page is scrolled another animation gets added to the page.

    Thats obviously NOT happening on your test page - the animation is only firing once:

    http://offers.premierinc.com/Scroll-Test_Scroll-Test.html

    So Im going to have a look and see why its not working on your actual page.