Skip to content

Instantly share code, notes, and snippets.

@glennyboy
Last active July 23, 2020 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glennyboy/3829c4af0d6fcf86a3b920ffe4933954 to your computer and use it in GitHub Desktop.
Save glennyboy/3829c4af0d6fcf86a3b920ffe4933954 to your computer and use it in GitHub Desktop.
Height Always the same as Width
// Best - height always same as width
$(window).on("focus load resize scroll",function(){
$('.width-height').each(function() {
$(this).height($(this).width());
});
// height always same as width
var divWidth = $('.width-height').width();
$(window).on("focus load resize scroll",function(){
$('.width-height').css({"height": divWidth, "max-height": divWidth});
});
// height always same as width
var divWidth = $('.width-height').width();
$(window).on("focus load resize scroll",function(){
$('.width-height').height(divWidth);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment