Skip to content

Instantly share code, notes, and snippets.

@argyleink
Created February 14, 2016 21:57
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save argyleink/2127a7303126da960f70 to your computer and use it in GitHub Desktop.
Save argyleink/2127a7303126da960f70 to your computer and use it in GitHub Desktop.
Fix mobile layout thrashing from using VH's
var els = document.querySelectorAll('.vh-fix')
if (!els.length) return
for (var i = 0; i < els.length; i++) {
var el = els[i]
if (el.nodeName === 'IMG') {
el.onload = function() {
this.style.height = this.clientHeight + 'px'
}
} else {
el.style.height = el.clientHeight + 'px'
}
}
@renntbenrennt
Copy link

Hey, Adam, I found your command in Jen's tweet about 100vh issue.

Your solution is quite creative and impressive👍, but I wonder if this is a trade off with performance.🤔

Anyway, our team actually encountered 100vh issue not long ago, and we use the trick from this post to solve the problem.

Also a pretty neat trick!😆 the-trick-to-viewport-units-on-mobile

@argyleink
Copy link
Author

argyleink commented Jan 13, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment