resize - using jquery to vertically center container while respecting a media query -
i need jquery vertically center div on document ready , also if there resize of browser i'm having difficulty combining 2 scripts. can see below have call twice work in both instances. i'm sure there better way write little unsure of how clean.
$(document).ready(function() { if ($(window).width() >= 770){ var $el = $('#main'); $el.css('position', 'absolute').css({ left: ($(window).width() - $el.width()) / 2, top: ($(window).height() - $el.height()) / 2 }); } $(window).resize(function(){ if ($(window).width() >= 770){ var $el = $('#main'); $el.css('position', 'absolute').css({ left: ($(window).width() - $el.width()) / 2, top: ($(window).height() - $el.height()) / 2 }); } });
Comments
Post a Comment