Skip to content

Instantly share code, notes, and snippets.

@Comandeer
Last active August 29, 2015 14:04
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 Comandeer/f3d8dc03096b9eb450ab to your computer and use it in GitHub Desktop.
Save Comandeer/f3d8dc03096b9eb450ab to your computer and use it in GitHub Desktop.
rAF makeEqual
<!DOCTYPE html>
<html lang="pl" dir="ltr">
<head>
<meta charset="UTF-8">
<title>Ehhhh</title>
<style>
html, body
{
margin: 0;
padding: 0;
height: 100%;
}
.col
{
float: left;
width: 33%;
background: #f00;
}
.col:nth-child(2)
{
background: #0f0;
}
</style>
</head>
<body>
<div class="col">1</div>
<div class="col">2</div>
<div class="col">3</div>
<script>(function equalHeight(container, cols, prev)
{
var h = container.innerHeight ? container.innerHeight : container.scrollHeight;
if(prev !== h)
{
console.log('różne');
cols.forEach(function(col)
{
col.style.height = h + 'px';
});
prev = h;
}
requestAnimationFrame(function()
{
equalHeight(container, cols, prev);
});
}(window, [].slice.call(document.querySelectorAll('.col'))));</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment