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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:50:05+00:00 2026-06-05T06:50:05+00:00

I know you can set different durations for different properties with CSS transitions. But

  • 0

I know you can set different durations for different properties with CSS transitions. But is it possible to set different durations for the same property?

Example: I want a box to grow/shrink in width to length A quickly when hovered/mouse exits, but grow/shrink in width to length B slowly when a button is pressed, using a different class.

Here is an example:

http://jsfiddle.net/VDyPG/7/

At the moment, the box only grows quickly when hovered, it shrinks back slowly when the mouse exits. Of course this is expected, as the .box class has the slow duration speed applied, but is there a way around this? I have worked out a hacky way of doing it with setTimeout and an extra “fast” class, but it would be lovely if there was a more elegant way.

Note: I’m aware this can be done easily with jQuery. I’m really looking for it to work with CSS however, as the actual problem I’m facing outside of this isolated example is with 3D transforms. Kept it simple for the example. 🙂

CSS:

.box {
    background: red;
    width: 100px;
    height: 100px;
    margin: 10px;
    -webkit-transition: width 2s; 
}

.lengthA
{   
   width: 300px; 
   -webkit-transition-duration: 0.2s; /* Can this be used when class removed? */
}

.lengthB {
     width: 500px;    
}

jQuery:

$('.box').on('mouseenter', function() {

    $(this).addClass('lengthA');            

})

$('.box').on('mouseleave', function() {

    $(this).removeClass('lengthA');            

})    

$('.makeBig').on('click', function() {

    $('.box').toggleClass('lengthB');            

})

​HTML:

<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<button class="makeBig">Grow!</button>
​
  • 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-05T06:50:06+00:00Added an answer on June 5, 2026 at 6:50 am

    I believe you can by using a variant of this technique: http://css-tricks.com/different-transitions-for-hover-on-hover-off/ . I’m on my iPad right now, so won’t those out an example, but the gist of it is that you set a different transition on the hover pseudo selector.

    If you want to use jquery, then you can bind to the transitioned event to find out when the previous transition as finished, it’s worth noting that the naming isn’t consistent –

    You’ll want to use something like:

    $("div").bind("webkitTransitionEnd oTransitionEnd msTransitionEnd transitionEnd transitionend", function(){
      //code
    });
    

    As it seems that Firefox uses transitionend, rather than the correct transitionEnd.

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

Sidebar

Related Questions

I know you can set max heap size at startup using -Xmx but is
I know that you can set the print margin in Eclipse, but if I
I know that I can set expiration date for a cookie, but can I
any property can set the pin in google map bigger? from what i know,
I know listview can set scrollbar thumb in XML like this Android:scrollbarThumbVertical etc. But
Is this possible to set different textSize in one TextView? I know that I
i know HTML/CSS and want to learn WPF styling. how can i get started.
I know I can set a CultureInfo object with an specified culture in the
Here's an image: I would like to know how i can set the black
like in java I have: Class.getSuperClass().getDeclaredFields() how I can know and set private field

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.