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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -