Created
April 18, 2013 17:42
-
-
Save derekpcollins/5414704 to your computer and use it in GitHub Desktop.
A CodePen by Derek P. Collins. Content Slider - On Click - Click a section to grow the content. Uses jQuery to set/remove classes on click. Uses CSS for the animation itself. If you click on an expanded section of content it will reset.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="slider"> | |
<div class="slide"></div> | |
<div class="slide"></div> | |
<div class="slide"></div> | |
<div class="slide"></div> | |
<div class="slide"></div> | |
</div><!-- .slider --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.slider').on('click', function( event ) { | |
var $target = $(event.target); | |
if( $target.hasClass( 'grow' ) ) { | |
$(this).find( '.slide' ).removeClass( 'shrink grow' ); | |
} else { | |
$(this).find( '.slide' ).removeClass( 'grow' ).addClass( 'shrink' ); | |
$target.removeClass( 'shrink' ).addClass( 'grow' ); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@import "compass"; | |
.slider { | |
border: 2px solid #222; | |
-moz-border-radius: 5px; | |
-webkit-border-radius: 5px; | |
border-radius: 5px; | |
margin: 30px auto; | |
overflow: hidden; | |
width: 541px; | |
.slide { | |
border-left: 2px solid #222; | |
height: 200px; | |
float: left; | |
overflow: hidden; | |
-moz-transition: width .4s ease-out; | |
-webkit-transition: width .4s ease-out; | |
transition: width .4s ease-out; | |
width: 106px; | |
&:first-child { | |
border-left: 0; | |
} | |
&:hover { | |
cursor: pointer; | |
} | |
&.grow { | |
width: 310px; | |
} | |
&.shrink { | |
width: 55px; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment