Move elements around using jQuery
Published onI prefer not to duplicate code, so this gist allows for moving DOM elements on window resize, at 768px.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(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); | |
}); |