Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature affix events #11664

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions js/affix.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() })
Expand Down
22 changes: 22 additions & 0 deletions js/tests/unit/affix.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,26 @@ $(function () {
ok(!$affix.hasClass('affix'), 'affix class was not added')
})

test('should trigger affixed event after affix', function () {
var template = $('<div id="affixTarget"><ul><li>Please affix</li><li>And unaffix</li></ul></div><div id="affixAfter" style="height: 20000px; display:block;"></div>')
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)
})
})