Skip to content

Instantly share code, notes, and snippets.

@anythinggraphic
Last active March 6, 2021 01:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anythinggraphic/3683c5f61ca76899d1c8c3877430a4c1 to your computer and use it in GitHub Desktop.
Script to move elements around based on window width
// @link https://mattrad.uk/move-elements-around-using-jquery/
// Script to move elements around based on window width
jQuery(function($) {
// Store the references outside the event handler:
var $window = $(window);
var $pane1 = $('#search-dropdown');
var $pane2 = $('.social-icons');
function checkWidth() {
var windowsize = $window.width();
if (windowsize > 768) {
$pane1.detach().insertAfter('.logo-container');
$pane2.detach().insertAfter($pane1);
}
if (windowsize < 767) {
$pane1.detach().insertBefore('.banner-container');
$pane2.detach().insertAfter('.contact');
}
}
// Execute on load
checkWidth();
// Bind event listener
$(window).resize(checkWidth);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment