Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8992999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:05:41+00:00 2026-06-15T23:05:41+00:00

I have a sprite animation that I would like to play when the mouse

  • 0

I have a sprite animation that I would like to play when the mouse hovers over the object and then play in reverse and stop on the first frame whenever the mouse leaves the object.

This is what I have for the mouse enter animation:

$("#banner").mouseenter(function(){ $('#bannerstache').sprite({fps: 200, no_of_frames: 34,   play_frames:34}); });

Basically, when you hover over the banner, a mustache “grows” until it’s completed at frame 34. (Whereas, on frame 1, there is no mustache.)

I want this mustache to play in reverse and go back to frame 1 whenever the mouse leaves the hovered state.

The problem is, I’ve tried a few methods of reversing the playback, but it doesn’t always reverse back to the first frame.

How can I achieve this?

Thank you so much if you’re able to provide some input!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:05:42+00:00Added an answer on June 15, 2026 at 11:05 pm

    here’s something I whipped up from your problem description

    HTML:

    <div id="div1" class="testContainer"></div>
    

    CSS:

    .testContainer {height:100px;width:150px;background-color:#CCC;text-align:center;font-size:90px}​
    

    JavaScript:

    // arrSprite would be an array of images
    // each index represents a frame in your sprite
    // for the purposes of this test i'll create an array of integers
    var arrSprite1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
    
    // $div1 is a container within which we'll place our animation
    var $div1 = $('#div1');
    
    // create a new SpritePlayer() to handle our animation
    var player = new SpritePlayer($div1, arrSprite1, 100);
    
    // set the hover in/out event handler of our container.
    $div1.hover(player.forward, player.reverse);
    
    function SpritePlayer($container, arrSprite, speed) {
        var int, cur = 0, min = 0, max = arrSprite.length;
    
        // give $container the first frame in our sprite (arrSprite)
        $container.html(getFrame(min));
    
        return {
            forward: function () { playSprite(true); },
            reverse: function () { playSprite(false); }
        };
    
        function getFrame(i) { return arrSprite[i]; }
    
        function playSprite(forward) {
            var limit = forward ? max : min;
    
            clearInterval(int); int = setInterval(function() {
                $container.html(getFrame(forward ? ++cur : --cur));
                cur === limit && clearInterval(int); 
            }, speed);
        }
    };
    ​
    

    Live Demo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a really large PNG file that I would like to animate over
I have a sprite sheet, and would like to use it using UIImage in
I'm working with sprite animation (OpenGL + C++). I have some trouble working with
I have a 2D animation in Javascript, and I need a sprite to move
I have a sprite loaded from a PNG that has an alpha channel. The
I am trying to use sprite sheet animation in my application. The first POC
i have a cocos2d world, and a sprite/body that is moving fast . when
I've a sprite that on touch have to start move along the Y coord.
i have 3 images and i would like to repeat them, one after the
I have an animated Sprite that is drawn on the screen when I press

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.