Skip to content

Instantly share code, notes, and snippets.

@norcross
Created May 20, 2014 14:14
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 norcross/bdcc26041ddf35e01beb to your computer and use it in GitHub Desktop.
Save norcross/bdcc26041ddf35e01beb to your computer and use it in GitHub Desktop.
set publish box to float down side of editor
$( 'div#postbox-container-1' ).each(function() {
// set the float box
var pubBox = $( this ).find( 'div#submitdiv' );
// get our sizes and offsets
var pubWth = ( pubBox ).width();
var offTop = $( 'div#postbox-container-1' ).offset().top;
var offRgt = ( $( window ).width() - ( pubBox.offset().left + pubBox.outerWidth() ) );
console.log( offRgt );
// add our floater
$( pubBox ).before( '<span class="float-block"></span>' ).addClass( 'box-floater' );
// set our two items to check and compare
var catcher = $( 'span.float-block' );
var sticky = $( 'div.box-floater' );
// start the scrolling
$( window ).scroll( function() {
if( isScrolledTo( sticky ) ) {
sticky.css({
'width' : pubWth + 'px',
'position' : 'fixed',
'top' : offTop + 'px',
'right' : offRgt + 'px',
'z-index' : '9999',
});
}
if ( ( offTop + 10 ) > sticky.offset().top ) {
sticky.removeAttr( 'style' );
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment