Hi,
I am trying to modify a plugin for Wordpress called Sharebar (site|demo). It is a social bar that "floats" next to your entry content. I say float in quotations because it is just a position:absolute object (this removes it's physical mass and sticks it to the top of the container). As you scroll down, the object transitions to position:fixed, so that it stays at the side.
What I want to change in this plugin is to make this bar not go past it's container; it should turn into position:absolute; bottom:0 as you scroll into the area beneath the entry content (the comments, the footer, etc).The reason I need this is because I am putting an indent into my entry content area, just like CNN.com does. It reduces the readable area to 550px (great for articles) and it ensures that the bar is tucked inside the body, rather than outside, which can pose problems for tablet screens.
I don't really understand the javascript behind this functionality, so I am asking for some advice. Here is the javascript code. Again, I really just want it to become position:absolute; bottom:0 when it reaches the botto of my div.content. Any help would be appreciated.
Code:
/*
* ShareBar - Creates a dynamic, vertical sharing bar to the left of a WordPress post and hides it if browser window is too small
* Copyright 2010 Monjurul Dolon, http://mdolon.com/
* Released under the MIT, BSD, and GPL Licenses.
* More information: http://devgrow.com/sharebar
*/
jQuery.fn.sharebar = function(options) {
var defaults = {horizontal: true, swidth: 65, minwidth: 1000, position: 'left', leftOffset: 20, rightOffset: 10};
var opts = jQuery.extend(defaults, options); var o = jQuery.meta ? jQuery.extend({}, opts, jQueryjQuery.data()) : opts;
var w = jQuery(window).width();
var sharebar = jQuery('#sharebar');
var sharebarx = jQuery('#sharebarx');
var parent = jQuery(sharebar).parent().width();
var start = sharebar_init();
function sharebar_init(){
jQuery(sharebar).css('width',o.swidth+'px');
if (o.position == 'left') jQuery(sharebar).css('marginLeft',(0-o.swidth-o.leftOffset));
else {
jQuery(sharebar).css('marginLeft',(parent+o.rightOffset));
}
if(w < o.minwidth && o.horizontal) jQuery(sharebarx).slideDown();
else jQuery(sharebar).fadeIn();
jQuery.event.add(window, "scroll", sharebar_scroll);
jQuery.event.add(window, "resize", sharebar_resize);
return jQuery(sharebar).offset().top;
}
function sharebar_resize() {
var w = jQuery(window).width();
if(w<o.minwidth){
jQuery(sharebar).fadeOut();
if(o.horizontal) jQuery(sharebarx).slideDown();
}else{
jQuery(sharebar).fadeIn();
if(o.horizontal) jQuery(sharebarx).slideUp();
}
}
function sharebar_scroll() {
var p = jQuery(window).scrollTop();
var w = jQuery(window).width();
jQuery(sharebar).css('position',((p+10)>start) ? 'fixed' : 'absolute');
jQuery(sharebar).css('top',((p+10)>start) ? '10px' : '');
}
};