My solution, inspired by @niaccurshi's:
Instead of hard-coding a padding-top, create an invisible duplicate element that takes up the same amount of space, but only while the original element is affixed.
JS:
var $submenu = $(".submenu");
// To account for the affixed submenu being pulled out of the content flow.
var $placeholder = $submenu.clone().addClass("affix-placeholder");
$submenu.after($placeholder);
$submenu.affix(…);
CSS:
.affix-placeholder {
/* Doesn't take up space in the content flow initially. */
display: none;
}
.affix + .affix-placeholder {
/* Once we affix the submenu, it *does* take up space in the content flow. But keep it invisible. */
display: block;
visibility: hidden;
}