Skip to content

Instantly share code, notes, and snippets.

@andreiglingeanu
Created January 30, 2014 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreiglingeanu/8718435 to your computer and use it in GitHub Desktop.
Save andreiglingeanu/8718435 to your computer and use it in GitHub Desktop.
/*##########################################################################################
Prepend <span> in Flickr Widget
##########################################################################################*/
jQuery(document).ready(function($){
$('.ewd-banner-fixed').closest('.widget.widget_text').addClass('affix-banner');
var addFixed = false;
$(window).scroll(function (e) {
// config
var whenToFlickr = 0; // px
var whenToFlickrBottom = 80; // px
var fromBottom = 60; // px
var offsetY = $(window).scrollTop();
var $flyingAdd = $('.affix-banner');
if ($flyingAdd.length) { return; }
var bottom = $flyingAdd.prev().offset().top + $flyingAdd.prev().height();
if (bottom - offsetY < -whenToFlickr) {
if (!$('.affix-banner').hasClass('fixed')) {
$('.affix-banner').addClass('fixed');
addFixed = true;
};
} else if ($('.affix-banner').hasClass('fixed')) {
$('.affix-banner').removeClass('fixed');
addFixed = false;
}
if (addFixed) {
var scrollFromBottom = $(document).height() - offsetY - $(window).height();
var bottomFooterTop = $('.td-footer-wrap').offset().top;
var footerOffset = (bottomFooterTop - offsetY) - ($flyingAdd.height() + whenToFlickrBottom);
$flyingAdd.css('margin-top', (footerOffset < 0 ? footerOffset - fromBottom : 0));
};
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment