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' ? position.top - scrollTop : null
+ 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() })
+ this.$element.offset({ top: scrollHeight - offsetBottom - this.$element.height() })
}
}