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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:37:53+00:00 2026-05-28T03:37:53+00:00

I have the following jQuery code that hides and shows a label when user

  • 0

I have the following jQuery code that hides and shows a label when user interacts with text box. Some scenarios:

1.) User focus, label should be at 50% opacity
2.) User types, label should be at 0% opacity
3.) User removes all content but remains focused, label should be at 50% opacity
4.) User removes all content and focus, label should be at 0% opacity
5.) User types content and focus, label should be at 0% opacity

So in a nutshell if input has value then no label, if focused it’s at 50% and if no value then at 100% opacity.

The code is as follows:

            $('label.placeholder').each(function() {

                var label = $(this);

                var input = label.next('input');

                label.click(function()
                {
                    input.focus();
                });

                input.bind('keyup keydown focus click check change paste copy', function()
                {
                    if (input.val().length > 0)
                    {
                        label.animate({ opacity: 0 }, 200);
                    }
                    else
                    {
                        label.animate({ opacity: .6 }, 200);
                    }

                }).bind('blur', function()
                {
                    label.animate({ opacity: 1 }, 200);

                });

The problem though is that if a user types in fast or does multiple actions then it can cause the fade back in or out to take a while as it has to go through all the checks for each scenario for each interaction callback. A good example is to type in a load of text and then delete it all again and you will see it take a while to reshow the label.

Any ideas on how to prevent this? http://jsfiddle.net/fFGM7/

  • 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-28T03:37:54+00:00Added an answer on May 28, 2026 at 3:37 am

    Use .stop() before all your animations. I believe that will fix it:

    $(label).stop().animate({ opacity: 1 }, 200);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following JQuery code that worked perfect in C#/Asp.net 2.0 to call
I am having a link <a id=test href=text.php>test</a> I have the following jquery code
I have the following code that isn't working in IE, any thoughts? <script type=text/javascript
I have the following code which shows nested ul and hides the other open
I have the following JQuery code that processes a GET request upon page load:
I've got the following code that shows a lightbox 'please wait' box, then does
I have the following jquery code that allows me to use tabs, to tab
i have the following jquery code. basically i will have several overlapped divs and
I have the following JQuery code which does similar functionality like Stackoverflow where the
I have the following JQuery code: // When the document is ready, start firing

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.