You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On this question, the post will shift once you scroll down far enough for the buttons to be sticky. This is because it has over 10k upvotes. I can't really fix this without causing the vote buttons to lag (à la the MutationObserver problem), but I hopefully improved it with the code below.
Also, you can see that the buttons will be covered by the topbar:
Here's the solution I wrote (though I don't have enough rep to check if it works in the review section on SO):
stickyVoteButtons: function() {
// Description: For making the vote buttons stick to the screen as you scroll through a post
//https://github.com/shu8/SE_OptionalFeatures/pull/14:
//https://github.com/shu8/Stack-Overflow-Optional-Features/issues/28: Thanks @SnoringFrog for fixing this!
stickcells();
$(document).on('sox-new-review-post-appeared', stickcells);
$(window).scroll(function() {
stickcells();
});
function stickcells() {
var $votecells = $('.votecell');
$votecells.each(function() {
var $topbar = ($('.so-header').length) ? $('.so-header') : $('.topbar'),
topbarHeight = $topbar.outerHeight(),
offset = $(".review-bar").outerHeight();
if ($topbar.css('position') == 'fixed' && !sox.location.on('/review'))
offset += topbarHeight;
else
offset += 5; //For some reason I have to add the bottom margin of ".review-bar"
var $voteCell = $(this),
$vote = $voteCell.find('.vote'),
vcOfset = $voteCell.offset(),
scrollTop = $(window).scrollTop(),
realHeight, endPos;
$voteCell.css('min-width', Math.floor($vote.width()));
if ($vote.length && $vote.children().last().length && $voteCell.next().length) { //These values strangely alternate between existing and not existing. This if statement insures we only get their values when they exist, so no errors.
realHeight = $vote.children(':not(:hidden, .message-dismissable)').last().offset().top + $vote.children(':not(:hidden, .message-dismissable)').last().height() - $vote.offset().top; //Get the original height; the difference between the last child and the first child's position
endPos = $voteCell.next().offset().top + $voteCell.next().height() - 51; //I think a bit above the end of the post (where the "edit", "delete", etc. buttons lie) is a good place to stop the stickiness.
}
$voteCell.on('DOMNodeInserted', function() { //Fix dismissable message boxes, like "Please consider adding a comment if you think this post can be improved." when downvoting
$vote.find('.message-dismissable').css({
position: "absolute",
"white-space": "nowrap"
})
})
if (vcOfset.top + realHeight < endPos - 25 && vcOfset.top < scrollTop + offset) { //Left condition is to get rid of a sticky zone on extremely short posts. Right condition allows stickiness unless we're above the post.
if (scrollTop + offset + realHeight < endPos) { //Allow stickiness unless we've scrolled down past the post.
$vote.css({
position: 'fixed',
top: offset
});
} else {
$vote.css({
position: 'absolute',
top: endPos - realHeight //Leave the button at its bottommost position
});
}
} else {
$vote.removeAttr('style'); //Remove any stickiness
}
});
}
},
Installed Version: 2.0.29 Environment: Tampermonkey
Current Behaviour
On this question, the post will shift once you scroll down far enough for the buttons to be sticky. This is because it has over 10k upvotes. I can't really fix this without causing the vote buttons to lag (à la the MutationObserver problem), but I hopefully improved it with the code below.
Also, you can see that the buttons will be covered by the topbar:
Here's the solution I wrote (though I don't have enough rep to check if it works in the review section on SO):
Features Enabled
The text was updated successfully, but these errors were encountered: