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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:48:25+00:00 2026-05-30T18:48:25+00:00

I’ve run into an interesting case that isn’t explicitly covered in the W3C CSS

  • 0

I’ve run into an interesting case that isn’t explicitly covered in the W3C CSS Transitions spec or the MDN CSS Transitions doc that I thought I would share because it cost me a bit of time.

If you “change” a CSS transitioned property to the same value then no transitioned event is fired. As I think about I can see why this would be the default behavior, but it can easily cause issues for the unsuspecting developer with something like this:
$("#test").css("opacity", "1").bind("transitionend", doneFn);

In the above code, if the element in question happens to have a opacity of 1 then the doneFn will never be called. Also see http://jsfiddle.net/studgeek/Xj8TB/.

To make this is a question, is there a good workaround for handling this?

You could compare the property value to the existing property value to the existing property value but that is trickier than it sounds to do it well because css property values can take so many forms – different units, and even string values like auto. So you really have to test the objects actual state, which of course needs to be done different for each property. Ugh.

  • 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-30T18:48:26+00:00Added an answer on May 30, 2026 at 6:48 pm

    One work-around would be to make your own jQuery method for setting a CSS value that would handle everything for you. It would get the current value of the property, set the new value, check to see if the value had changed. If it had not, then it would fire the completion function manually:

    // globally set this to the right transition event for the current browser
    // modernizr has ways of using feature detection to know which is the right way to set this
    var transitionEvent = "webkitTransitionEnd";
    
    jQuery.fn.transitionTo = function(prop, value, completeFn) {
        var origValue, item;
        for (var i = 0, len = this.length; i < len; i++) {
            item = jQuery(this[i]);
            origValue = item.css(prop);
            item.css(prop, value);
    
            // if value hasn't changed           
            if (origValue == item.css(prop)) {
                completeFn.apply(this[i]);
            } else {
                this.one(transitionEvent, completeFn);
            }
        }
    }
    

    In your example above, it would work like this:

    $("#test").transitionTo("opacity", "1", doneFn);
    

    Working example here: http://jsfiddle.net/jfriend00/LHdGR/

    This plug-in could be expanded to support passing a map of multiple properties like the .css() supports too.

    The only other option I can think of is to read the transtionDuration and set a timeout value for slightly longer than that. If the transitionEnd event fires, you cancel the timeout. If it doesn’t fire, the timeout can manually fire the transitionEnd event. The code for this could work like this:

    var transitionEvent = "webkitTransitionEnd";
    var transitionDuration = "WebkitTransitionDuration";
    
    // get transition duration in decimal seconds
    // this only returns the first transition time if there are multiple ones specified
    jQuery.fn.getDuration = function() {
        var val = this.css(transitionDuration);
        if (!val) {
            val = "0s";
        }
        var num = parseFloat(val);
        var units = val.replace(/\d\., /g, "");
        if (units.indexOf("ms") == 0) {
            num /= 1000;
        }
        return(num);
    }
    
    // set a guaranteed transition event that will always fire, even if
    // no CSS transition is triggered
    jQuery.fn.setTransitionEvent = function(completeFn) {
        var item, duration;
        for (var i = 0, len = this.length; i < len; i++) {
            item = jQuery(this[i]);
            duration = Math.ceil((Number(item.getDuration()) + 0.1) * 1000);
            (function(t, o) {
                var timeout = setTimeout(function() {
                    completeFn.apply(o);
                    o.unbind(transitionEvent);
                }, duration);
                o.one(transitionEvent, function() {
                    clearTimeout(timeout);
                });
            })(duration, item);
        }
    }
    

    Working example here: http://jsfiddle.net/jfriend00/hxevW/

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I am currently running into a problem where an element is coming back from
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post

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.