question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enhancement: Step animations through custom easings

See original GitHub issue

Hi,

I wanted to animate a background image (sprite sheet) to replace a css3 animation. The current CSS equivalent is:

@keyframes play {
  from { background-position:    0px; }
  to { background-position: -600px; }
}

.loader {
    width: 20px;
    height: 20px;
    background-image: url("../img/loader.png");
    @include animation(play 1s steps(10) infinite);
}

My current implementation with velocity is:

window.setInterval(function() {
    $element.velocity({
        'background-position-x': ['-600px', '0px']
    }, {
        duration: 1000
    });
}, 1000);

But it animates the background position with a step that I can’t control. I would like to increment it by 20px each frame (the width of the loader), otherwhise it won’t work as expected.

Is this possible with velocity ? Maybe with the easing function ?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
ocombecommented, Jun 19, 2014

Turns out the step function is really simple:

(function() {
    var Container = (window.jQuery || window.Zepto || window);

    if(!Container.Velocity || !Container.Velocity.Utilities) {
        console.log("Velocity UI Pack: Velocity must first be loaded. Aborting.");
        return;
    }

    Container.Velocity.Easings["steps"] = function(p, opts) {
        return Math.round(p*opts.steps)*(1/opts.steps);
    }
})();
0reactions
julianshapirocommented, Feb 16, 2015

thanks, @ocombe! awesome use

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add easing to custom animation function - Stack Overflow
But what it basically comes down to is that you are changing 'the form' of the easing function by the following properties:.
Read more >
The Basics of easing - web.dev
Learn how to soften and give weighting to your animations. ... You can also go completely custom with your easing, which gives you...
Read more >
animation-timing-function - CSS: Cascading Style Sheets | MDN
The easing function that corresponds to a given animation, as determined by animation-name . The non-step keyword values (ease, linear, ...
Read more >
Smooth Transitions With Easing in Figma and After Effects
Download Figma UI Kits: ...
Read more >
Incorporating elastic ease in CSS animations - LogRocket Blog
One simple yet fantastic solution is to use cubic-bezier ease to get a single-step elastic. You can do so by giving the fourth...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found