transition.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* ========================================================================
  2. * Bootstrap: transition.js v3.4.1
  3. * https://getbootstrap.com/docs/3.4/javascript/#transitions
  4. * ========================================================================
  5. * Copyright 2011-2019 Twitter, Inc.
  6. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  7. * ======================================================================== */
  8. +function ($) {
  9. 'use strict';
  10. // CSS TRANSITION SUPPORT (Shoutout: https://modernizr.com/)
  11. // ============================================================
  12. function transitionEnd() {
  13. var el = document.createElement('bootstrap')
  14. var transEndEventNames = {
  15. WebkitTransition : 'webkitTransitionEnd',
  16. MozTransition : 'transitionend',
  17. OTransition : 'oTransitionEnd otransitionend',
  18. transition : 'transitionend'
  19. }
  20. for (var name in transEndEventNames) {
  21. if (el.style[name] !== undefined) {
  22. return { end: transEndEventNames[name] }
  23. }
  24. }
  25. return false // explicit for ie8 ( ._.)
  26. }
  27. // https://blog.alexmaccaw.com/css-transitions
  28. $.fn.emulateTransitionEnd = function (duration) {
  29. var called = false
  30. var $el = this
  31. $(this).one('bsTransitionEnd', function () { called = true })
  32. var callback = function () { if (!called) $($el).trigger($.support.transition.end) }
  33. setTimeout(callback, duration)
  34. return this
  35. }
  36. $(function () {
  37. $.support.transition = transitionEnd()
  38. if (!$.support.transition) return
  39. $.event.special.bsTransitionEnd = {
  40. bindType: $.support.transition.end,
  41. delegateType: $.support.transition.end,
  42. handle: function (e) {
  43. if ($(e.target).is(this)) return e.handleObj.handler.apply(this, arguments)
  44. }
  45. }
  46. })
  47. }(jQuery);