Skip to content

Instantly share code, notes, and snippets.

@LucasJAlba
Created May 9, 2014 05:21
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 LucasJAlba/a12a6b2e8a8fab956865 to your computer and use it in GitHub Desktop.
Save LucasJAlba/a12a6b2e8a8fab956865 to your computer and use it in GitHub Desktop.
A Pen by Lucas Alba.
<div class='someRandomPartofyourPage'>
<div class="ratio aspect4by3">
<iframe src="//www.youtube.com/embed/j3vHv4lNvg4"></iframe>
<iframe src="//www.youtube.com/embed/lBgmmuEe9HQ"></iframe>
<iframe src="//www.youtube.com/embed/06CIpf_eSoc"></iframe>
</div>
<button id='ratioToggle'>Toggle Ratio</button>
<div class='nav'>
<button data-dir='left' data-slide-in='-100' data-slide-out='100'>Prev Video</button>
<button data-dir='right' data-slide-in='100' data-slide-out='-100'>Next Video</button>
</div>
</div>
$('#ratioToggle').click(function(){
$('.ratio').toggleClass('aspect16by9').toggleClass('aspect4by3');
});
$('.nav > *').click(function(){
if($('.ratio > * ').eq(0).attr('data-lock') == 'true') return;
$('.ratio > * ').attr('data-lock','true');
var timer = 1000;
var swapDir = $(this).attr('data-dir');
if(swapDir=='left'){
$('.ratio > * ').eq(-2)
.css('left',$(this).attr('data-slide-in')+'%')
.animate({left: "0" }, timer)
.siblings().eq(-1)
.animate({ left: $(this).attr('data-slide-out')+'%' }, timer,function(){
$('.ratio > * ').eq(-1).detach().prependTo('.ratio');
$('.ratio > * ').attr('data-lock','false');
});
}
else if(swapDir=='right'){
$('.ratio > * ').eq(0)
.detach()
.appendTo('.ratio')
.css('left',$(this).attr('data-slide-in')+'%')
.animate({left: "0" }, timer)
.end()
.siblings().eq(-1)
.animate({ left: $(this).attr('data-slide-out')+'%' }, timer,function(){
$('.ratio > * ').attr('data-lock','false');
});
}
});
.someRandomPartofyourPage{
width: 80%;
margin-left:auto;
margin-right:auto;
}
.ratio {
display: inline-block;
position: relative;
width: 100%;
overflow: hidden;
}
.ratio::after {
content:'';
display: block;
}
.ratio > * {
position: absolute;
width: 100%;
height: 100%;
}
.aspect16by9::after {margin-top: 56.25%;}
.aspect4by3::after {margin-top: 75%;}
button{ float:left;width:33.33%;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment