At the moment I have a running fiddle that I am trying to get a css3 opacity transition to fire off when I add a class to it. The basic set up is that I click a button and then through jquery I add a div to the dom and after I add that element to the dom I then add a class to it. The adding class to that new dom element is suppose to kick off my transition but it is not, the only thing that is happening is that the element is being showed but the opacity transition isnt working. Any help will be much appreciated, I am leaving a link to the fiddle here fiddle link .And yes I know i could do the fade in with just jquery, but this is just a experiment , that would probably be used to kick off other css transition other then opacity
-
It does indeed only seem to work if the class is predefined...adding it dynamically will not execute the transition. Maybe this is still a bug to be solved.Bas Slagter– Bas Slagter2011-10-10 15:28:36 +00:00Commented Oct 10, 2011 at 15:28
-
Thats what i was thinking to, but is till find it hard to believe that this has not been noticed by chrome or firefox dev'sLawrence– Lawrence2011-10-10 15:39:12 +00:00Commented Oct 10, 2011 at 15:39
Add a comment
|
2 Answers
I have encountered this problem before, the only workaround I've found is adding a setTimeout to let the DOM notice there's a new element. It can be zero ms and it will still work:
$('button').live('click', function() {
$(this).after("<div class='fade'>This is just a test</div>")
setTimeout(function(){$(".fade").addClass("in");}, 0)
});
1 Comment
BinaryTox1n
Well that is really annoying. Thanks for the solution.