dgmike
3/11/2011 - 11:17 AM

Extracted from http://www.omgubuntu.co.uk this script puts the entry-share box on absolute position if the browser scrolls out of then

Extracted from http://www.omgubuntu.co.uk this script puts the entry-share box on absolute position if the browser scrolls out of then

// From www.omgubuntu.co.uk

$j = jQuery.noConflict();
$j(document).ready(function () {
    if ($j(".entry-share").length) {
        console.log($j(".entry-share").length);
        var shareBar = $j(".entry-share");
        var above = $j(".entry-meta").height() + $j(".entry-title").height() + 480;
        $j(window).scroll(function () {
            var headerStop = $j("body").height() - 283;
            var absolutePos = $j("#content").height() - 51;
            var upTop = $j(this).scrollTop();
            var barPos = shareBar.css('position');
            if (upTop > above) {
                if (upTop + 40 > headerStop) {
                    if (barPos != 'absolute') shareBar.css({
                        'position': 'absolute',
                        'top': absolutePos
                    });
                } else if (barPos != 'fixed') {
                    shareBar.css({
                        'position': 'fixed',
                        'top': '-10px'
                    });
                    $j(".entry-meta").css({
                        'padding': '0 0 40px 0'
                    });
                }
            } else if (barPos != 'static') {
                shareBar.css("position", "static");
                $j(".entry-meta").css({
                    'padding': '0'
                });
            }
        });
    }
});