2014-07-08, 01:39 PM
Basically I'm trying to get my div #panel to stick to the top of the screen when i scroll down past it, follow my scrolling but return to its original place if i scroll up past it.
So I jumped over to stackoverflow to look at some stuff that should do this.
After going through a few discussions and demo's of how to do it, I saw a smooth demo (no laggy scrolling or catching up) so decided to copy what they did.
I added this javascript into a file called stickypanel.js (I checked the console on page load, it gets the file fine)
Added this to my themes global.css
and I put the anchor div above the panel div
Nothing appears to be happening whatsoever, has anybody here used any method for something like this successfully?
So I jumped over to stackoverflow to look at some stuff that should do this.
After going through a few discussions and demo's of how to do it, I saw a smooth demo (no laggy scrolling or catching up) so decided to copy what they did.
I added this javascript into a file called stickypanel.js (I checked the console on page load, it gets the file fine)
function sticky_relocate() {
var window_top = $(window).scrollTop();
var div_top = $('#panel-anchor').offset().top;
if (window_top > div_top) {
$('#panel').addClass('stick');
} else {
$('#panel').removeClass('stick');
}
}
$(function () {
$(window).scroll(sticky_relocate);
sticky_relocate();
});
Added this to my themes global.css
#panel.stick {
position: fixed;
top: 0;
z-index: 10000;
border-radius: 0 0 0.5em 0.5em;
}
and I put the anchor div above the panel div
<div id="panel-anchor"></div>
<div id="panel">{$welcomeblock}</div>
Nothing appears to be happening whatsoever, has anybody here used any method for something like this successfully?