Skip to content

Instantly share code, notes, and snippets.

@argyleink argyleink/vh-fix.js
Created Feb 14, 2016

Embed
What would you like to do?
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'
}
}
@SeasonLeee

This comment has been minimized.

Copy link

SeasonLeee commented Jan 11, 2020

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

This comment has been minimized.

Copy link
Owner Author

argyleink commented Jan 13, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.