CSS3 transition event Listener with jQuery

余生长醉 提交于 2019-11-28 09:10:56

in jQuery you should use bind() or on() method:

$(this).parent().bind( 'transitionend', function() {alert("1"); });
graygilmore

Also take note that if you are running multiple transitions on an element (eg. opacity and width) that you'll get multiple transitionEnd callbacks.

If you're using jQuery to bind an event to a div's transition end, you might want to consider using one() function.

$(this).parent().one("webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend", function() {
    // your code when the transition has finished
});

This means that the code will only fire the first time. So, if you had four different transitions happening on the same element, your callback will only fire once.

this.parentNode returns a javascript object. It has a property .addEventListener $(this).parent()returns a jQuery object. It does not have a property .addEventListener

Try this instead,

$(this).parent().on('webkitTransitionEnd oTransitionEnd transitionend msTransitionEnd', function() {
    alert("1");
})

If the first one really works (I doubt it because it should require a vendor prefix), then this should work too:

$(this).parent().on('transitionend', function() {
    alert("1");
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!