2

I've been working with this for a few hours and it's driving me mad. I've got a modal window that pops up on click of a link. It's got a CSS transition so it fades in. I need to have a callback for when that transition completes. So I dug up this event listener:

$('#tagBox').addEventListener(
    'webkitTransitionEnd', 
    function(event) { 
        alert( "Finished transition!" ); }, 
    false );

I'm in Safari, but that code returns this error:

TypeError: 'undefined' is not a function (evaluating '$('#tagBox').addEventListener( 'webkitTransitionEnd', function(){ alert( "Finished transition!" ) }, false )')

Is my syntax correct? I can do alert($('#tagBox')) and it returns [object] so it's finding the modal element. Why does it say undefined is not a function?

Thanks.

3
  • Why don't you use bind instead? Commented Mar 19, 2012 at 1:54
  • That'll repeat over and over, right? Commented Mar 19, 2012 at 2:01
  • Only when the eventType has been triggered… Commented Mar 19, 2012 at 11:41

4 Answers 4

6

$('#tagBox') returns a jQuery element which doesn't have addEventListener method which is a native method. You need to get the raw DOM before calling addEventListener by doing:

$('#tagBox')[0].addEventListener(// your code
Sign up to request clarification or add additional context in comments.

Comments

2

Something should like to be:

$('#tagBox').bind('webkitTransitionEnd', function() {
   //....
});

And if you want to fire just once, you could use .one:

$('#tagBox').one('webkitTransitionEnd', function() {
   //....
});

5 Comments

This repeats over and over, how can I have it just happen on complete
The event is fired when transition ends, what do you mean by "repeats over and over"?
Sorry, I have a bunch of transitions going on within #tagbox. Fixed by doing $(this).unbind() inside that bind event.
@JacksonGariety You could use .one for that.
How can I combine them so It works in opera and firefox as well? How do I add in the oTransitionEnd?
1

Are you missing the event parameter?

box.addEventListener( 
'webkitTransitionEnd', 
function( event ) { 
     alert( "Finished transition!" ); 
}, false );

Comments

1

If you're using the most recent version of jquery 1.7+ you'll actually be looking for "on" http://api.jquery.com/on/ which will allow you to add your events to it.

$('#tagBox').on('webkitTransitionEnd', function(event) { alert('whatever'); });

Combined with jQuery off:

$('#tagBox').on('webkitTransitionEnd', function(event) { 
    $('#tagBox').off('webkitTransitionEnd');
    alert('whatever'); 
}); 

1 Comment

That is looping over and over and over. I want tit to just happen once.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.