mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-11 16:14:04 +02:00
fixes #11720 - Add events trigger to affix
This commit is contained in:
12
js/affix.js
12
js/affix.js
@@ -67,10 +67,20 @@
|
||||
if (this.affixed === affix) return
|
||||
if (this.unpin) this.$element.css('top', '')
|
||||
|
||||
var affixType = 'affix' + (affix ? '-' + affix : '')
|
||||
var e = $.Event(affixType + '.bs.affix')
|
||||
|
||||
this.$element.trigger(e)
|
||||
|
||||
if (e.isDefaultPrevented()) return
|
||||
|
||||
this.affixed = affix
|
||||
this.unpin = affix == 'bottom' ? this.getPinnedOffset() : null
|
||||
|
||||
this.$element.removeClass(Affix.RESET).addClass('affix' + (affix ? '-' + affix : ''))
|
||||
this.$element
|
||||
.removeClass(Affix.RESET)
|
||||
.addClass(affixType)
|
||||
.trigger($.Event(affixType.replace('affix', 'affixed')))
|
||||
|
||||
if (affix == 'bottom') {
|
||||
this.$element.offset({ top: document.body.offsetHeight - offsetBottom - this.$element.height() })
|
||||
|
@@ -22,4 +22,29 @@ $(function () {
|
||||
ok(!$affix.hasClass('affix'), 'affix class was not added')
|
||||
})
|
||||
|
||||
test('should trigger affixed event after affix', function () {
|
||||
stop()
|
||||
|
||||
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('affix.bs.affix', function (e) {
|
||||
ok(true, 'affix event triggered')
|
||||
}).on('affixed.bs.affix', function (e) {
|
||||
ok(true,'affixed event triggered')
|
||||
$('#affixTarget').remove()
|
||||
$('#affixAfter').remove()
|
||||
start()
|
||||
})
|
||||
|
||||
setTimeout(function () {
|
||||
window.scrollTo(0, document.body.scrollHeight)
|
||||
setTimeout(function () { window.scroll(0,0) }, 0)
|
||||
},0)
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user