Fix sticky feeds extension

Scroll bar appears even if the window is at the top of the screen.

Fix https://github.com/FreshRSS/FreshRSS/issues/697
This commit is contained in:
Marien Fressinaud 2015-01-14 23:57:35 +01:00
parent b0e741d20a
commit be3da9984e
2 changed files with 38 additions and 36 deletions

View file

@ -1,37 +1,39 @@
"use strict"; "use strict";
var sticky_feeds_aside_tree = null, var sticky_feeds = {
sticky_feeds_initial_pos_top = 0, tree: null,
sticky_feeds_window = null; initial_pos_top: 0,
width: 0,
window: null,
init: function() {
if (!window.$) {
window.setTimeout(sticky_feeds.init, 50);
return;
}
sticky_feeds.tree = $('#aside_feed .tree');
if (sticky_feeds.tree.length > 0) {
sticky_feeds.window = $(window);
sticky_feeds.initial_pos_top = sticky_feeds.tree.position().top;
sticky_feeds.tree.css('min-width', $('#aside_feed').width());
sticky_feeds.tree.addClass('sticky');
sticky_feeds.window.on('scroll', sticky_feeds.scroller);
sticky_feeds.scroller();
}
},
scroller: function() {
var pos_top_window = sticky_feeds.window.scrollTop();
if (pos_top_window < sticky_feeds.initial_pos_top) {
sticky_feeds.tree.css('top', sticky_feeds.initial_pos_top - pos_top_window + 10);
} else {
sticky_feeds.tree.css('top', 0);
}
},
};
function sticky_feeds_scroller() { window.onload = sticky_feeds.init;
var pos_top_window = sticky_feeds_window.scrollTop();
if (pos_top_window >= sticky_feeds_initial_pos_top &&
!sticky_feeds_aside_tree.hasClass('sticky')) {
sticky_feeds_aside_tree.addClass('sticky');
sticky_feeds_aside_tree.css('width', $('#aside_feed').width());
} else if (pos_top_window < sticky_feeds_initial_pos_top) {
sticky_feeds_aside_tree.removeClass('sticky');
}
}
function sticky_feeds_init() {
if (!window.$) {
window.setTimeout(init_sticky_feeds, 50);
return;
}
sticky_feeds_aside_tree = $('#aside_feed .tree');
if (sticky_feeds_aside_tree.length > 0) {
sticky_feeds_initial_pos_top = sticky_feeds_aside_tree.position().top;
sticky_feeds_window = $(window);
sticky_feeds_window.on('scroll', sticky_feeds_scroller);
sticky_feeds_scroller();
}
}
window.onload = sticky_feeds_init;

View file

@ -1,14 +1,14 @@
#aside_feed .tree.sticky { #aside_feed .tree.sticky {
position: fixed; position: fixed;
top: 0; bottom: 0; top: 0; bottom: 0;
margin: 0 0 60px; left: 0;
overflow: auto; margin-top: 0;
overflow-y: auto;
} }
@media(max-width: 840px) { @media(max-width: 840px) {
/* No effect on mobile */ /* No effect on mobile */
#aside_feed .tree.sticky { #aside_feed .tree.sticky {
position: static; position: static;
margin: 10px 0 50px;
} }
} }