diff --git a/js/affix.js b/js/affix.js index 7d111ecc4d08..d3f91f8717a4 100644 --- a/js/affix.js +++ b/js/affix.js @@ -71,6 +71,7 @@ this.unpin = affix == 'bottom' ? position.top - scrollTop : null this.$element.removeClass(Affix.RESET).addClass('affix' + (affix ? '-' + affix : '')) + this.$element.trigger($.Event((affix ? 'affixed' : 'unaffixed') + '.bs.affix')) if (affix == 'bottom') { this.$element.offset({ top: document.body.offsetHeight - offsetBottom - this.$element.height() }) diff --git a/js/tests/unit/affix.js b/js/tests/unit/affix.js index b74bc51e48bd..a1050993a115 100644 --- a/js/tests/unit/affix.js +++ b/js/tests/unit/affix.js @@ -22,4 +22,26 @@ $(function () { ok(!$affix.hasClass('affix'), 'affix class was not added') }) + test('should trigger affixed event after affix', function () { + var template = $('
') + template.appendTo('body') + var affixer = $('#affixTarget').affix( { + offset: $('#affixTarget ul').position() + }) + + $('#affixTarget').on('affixed.bs.affix', function (e) { + ok(true, 'affixed event triggered') + start() + }).on('unaffixed.bs.affix', function (e) { + ok(true,'unaffixed event triggered') + }) + + stop() + setTimeout(function () { + window.scrollTo(0,document.body.scrollHeight) + setTimeout(function () { + window.scroll(0,0) + },0) + },0) + }) })