Skip to content

Instantly share code, notes, and snippets.

Created January 9, 2014 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/8334175 to your computer and use it in GitHub Desktop.
Save anonymous/8334175 to your computer and use it in GitHub Desktop.
body {
padding:100px;
}
.top {
position:absolute;
top:0;
left:0;
}
.top.go {
width:100%;
overflow:hidden;
-webkit-transition: width 5s ease-in-out;
-moz-transition: width 5s ease-in-out;
-o-transition: width 5s ease-in-out;
transition: width 5s ease-in-out;
}
.top.purple {
background:#c3c;
}
.top.black {
background:#000;
}
.top.red {
background:#FF0000;
}
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery.min.js"></script>
<link href="http://getbootstrap.com/dist/css/bootstrap.css" rel="stylesheet" type="text/css" />
<script src="http://getbootstrap.com/dist/js/bootstrap.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<div class="top">top</div>
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active" data-color="black">
<img src="http://matgargano.com/books/1.png" alt="doggy!">
<div class="carousel-caption">
Caption black
</div>
</div>
<div class="item" data-color="red">
<img src="http://matgargano.com/books/2.png" alt="doggy!">
<div class="carousel-caption">
Caption red
</div>
</div>
<div class="item" data-color="purple">
<img src="http://matgargano.com/books/3.png" alt="doggy!">
<div class="carousel-caption">
Caption purple
</div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
<div class="add">Add</div>
<div class="remove">remove</div>
</body>
</html>
var setColor = function(){
$contents = jQuery('.top');
$contents.removeClass('go');
setTimeout(function(){
$active = $('.item.active');
color = $active.data('color');
$contents.html(color);
$contents.attr('class', 'top go');
$contents.addClass(color);
}, 1);
};
$('#carousel-example-generic').on('slid.bs.carousel', function () {
setColor();
});
jQuery(document).ready(function(){
setColor();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment