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

Fixes affix-top class not applying #15154

Closed
wants to merge 2 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
2 changes: 1 addition & 1 deletion js/affix.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
var colliderTop = initializing ? scrollTop : position.top
var colliderHeight = initializing ? targetHeight : height

if (offsetTop != null && colliderTop <= offsetTop) return 'top'
if (offsetTop != null && scrollTop <= offsetTop) return 'top'
if (offsetBottom != null && (colliderTop + colliderHeight >= scrollHeight - offsetBottom)) return 'bottom'

return false
Expand Down
30 changes: 30 additions & 0 deletions js/tests/unit/affix.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,34 @@ $(function () {
}, 16) // for testing in a browser
}, 0)
})

test('should affix-top when scrolling up to offset when parent has padding', function () {
stop()

var templateHTML = '<div id="padding-offset" style="padding-top: 20px;">'
+ '<div id="affixTopTarget">'
+ '<p>Testing affix-top class is added</p>'
+ '</div>'
+ '<div style="height: 1000px; display: block;"/>'
+ '</div>'
$(templateHTML).appendTo(document.body)

$('#affixTopTarget').bootstrapAffix({
offset: { top: 120, bottom: 0 }
})

$('#affixTopTarget')
.on('affixed-top.bs.affix', function () {
ok($('#affixTopTarget').hasClass('affix-top'), 'affix-top class applied')
start()
})

setTimeout(function () {
window.scrollTo(0, document.body.scrollHeight)

setTimeout(function () {
window.scroll(0, 119)
}, 0)
}, 0)
})
})