0
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-01-17 09:52:29 +01:00

Merge pull request #15154 from nickyod/affix-top-bug

This commit is contained in:
Chris Rebert 2014-11-17 18:19:55 -08:00
commit 4037990237
2 changed files with 30 additions and 1 deletions

View File

@ -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

View File

@ -68,4 +68,33 @@ $(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 }
})
.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)
}, 250)
}, 250)
})
})