Skip to content

Instantly share code, notes, and snippets.

@zeshanshani
Last active April 24, 2019 20:20
Show Gist options
  • Save zeshanshani/27f8401ea360b0f61c02 to your computer and use it in GitHub Desktop.
Save zeshanshani/27f8401ea360b0f61c02 to your computer and use it in GitHub Desktop.
Stretch banner to fill fullscreen but keep the height minimum so on smaller screens, content inside won't overlap.
// jQuery Window FullScreen Plugin
//
// Author: Zeshan Ahmed
// Author URI: http://www.zeshanahmed.com/
//
// = Replace .element_to_target with the your element selector
jQuery(document).ready(function($) {
var $win = $(window),
$element = $('.element_to_target'),
$wpadminbar = $('#wpadminbar');
function fullScreen( $el ) {
// You can add addtional elements here to add offset value.
// Mostly when fixed navbar is active and you want to offset
// it's value from the fullscreen section's height.
var winH = $win.height(),
wpadminbarH = $wpadminbar.height(),
finalHeight = $winH - $wpadminbarH;
// Replace "min-height" with "height" if you
// want to add fixed height.
$el.css( 'min-height', finalHeight );
}
$win.ready( fullScreen( $element ) ).resize(function() {
fullScreen( $element );
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment