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 6977393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:37:12+00:00 2026-05-27T17:37:12+00:00

I’ve a simple problem with animation my button. I can’t figure it out since

  • 0

I’ve a simple problem with animation my button. I can’t figure it out since I’m a beginner in jQuery (keep this in mind).

Please visit http://www.lionwebmedia.com and navigate to buttons which are under each project, now hover it. You should notice that the animation isn’t quite right. The button width is expanding but with text change (no delay) and we get ugly effect of letters coming in from the bottom expanding button height.

This screen will help you understand what i mean and how i want to solve this.

And here is jsfiddle of my code

I would appreciate any help.
Thanks!

  • 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-05-27T17:37:13+00:00Added an answer on May 27, 2026 at 5:37 pm

    First up

    I’ll refer you to JQuery Animate documentation.
    More specifically, take a look at how they make animation queues.

    $('#clickme').click(function() {
      $('#book').animate({
        width: 'toggle',
        height: 'toggle'
      }, {
        duration: 5000,
        specialEasing: {
          width: 'linear',
          height: 'easeOutBounce'
        },
        complete: function() {
          $(this).after('<div>Animation complete.</div>');
        }
      });
    });
    

    When the animation is complete, is where you want to add the text.


    Solution

    Here is a JSFiddle of a working solution.

    $('.projectContact').mouseenter(function() {
            $(this).animate({
                width: "95px"
            }, 250, function(){
                   $(this).text('Request a quote')
            });
    }).mouseleave(function(){
        $(this).animate({
            width: "16px"
        }, 250, function(){
            $(this).html("<img src=\"images/mail.png\">");
        });
    });
    

    I used mouseenter and mouseleave because they are not just more reliable, but also easier to read. As you can see, the last function parameter (animation complete) in the .animate is where you’ll want the change to occur.

    Also, you can add this to the style properties for the element, where you basically force the text to stay on one line, and hide everything that goes outside of bounds. This way, when you animate, the text won’t affect the container.
    CSS:

    .myButton{
        white-space: nowrap;
        overflow: hidden;
    }
    

    What you also could do, is make a class that contain the CSS, and then add/remove at the start/end of each animation, if you don’t want the CSS to interfere with the rest of your CSS.


    Final solution

    Alright, here is the final solution, with fades and everything. It’s not complete, but you get the picture.

    var current_element = "img";
    
    $('.projectContact').mouseenter(function() {
            var par = $(this);
            $('.projectContact '+current_element).animate({
                opacity: 0
            }, 250, function(){
                par.animate({
                    width: "95px"
                }, 250, function(){
                    par.html('<div>Request a quote</div>');
                    current_element = "div";
                });
            });
            inside = true;
    }).mouseleave(function(){
        var par = $(this);
            $('.projectContact '+current_element).animate({
                opacity: 0
            }, 250, function(){
                par.animate({
                    width: "16px"
                }, 250, function(){
                    par.html('<img src="http://www.hager.se/icons/icon_mail.gif">');
                    current_element = "img";
                });
            });
    });
    

    You can mess around with the animation times, but that is basically how you do it. I had to add a “div” to your “Request a quote” text, in order to be able to animate it individually. This way, you can play with it’s opacity as well.

    Good luck!


    Alternative solution

    Here’s a different approach where you edit the text/image of the element the instant you begin animating. This is the method you’re currently using. Note that the CSS white-space: nowrap; is required for this to work without making the animation “ugly”.

    $('.projectContact').mouseenter(function() {
            $(this).animate({
                width: "95px"
            }, 250).text('Request a quote');
    }).mouseleave(function(){
        $(this).animate({
            width: "16px"
        }, 250).html("<img src=\"images/mail.png\">");
    });
    

    Finishing thoughts

    It would be good practice to use .clearQueue, so that your animations don’t begin to pile up. It resets the animation queue and stops the animation, so, in this case, if the user quickly hovers in and out, the animation will proceed directly to the mouseleave animation.
    This is also particularly useful when a user for instance hovers in and out of the element twice or more, before the first animation sequence is complete, it prevents animation pileups.

    See it in use

    $('.projectContact').mouseenter(function() {
            $(this).animate({
                width: "95px"
            }, 250).text('Request a quote').clearQueue();
    }).mouseleave(function(){
        $(this).animate({
            width: "16px"
        }, 250).html("<img src=\"images/mail.png\">").clearQueue();
    });
    

    Alternatively you can use .stop, which does the same thing, but only for the current animation, not the entire animation queue.

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,

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.