cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmloctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <section class="content_accordion section">
				<header class="section_index">
					<h2>accordion</h2>
				</header>
				<div class="section_content">
					<dl class="content_accordion_child" data-accordion="open">
						<dt class="content_accordion_child_index">
							見出し1
							<span class="content_accordion_child_indexCap close">close</span>
							<span class="content_accordion_child_indexCap open">open</span>													
						</dt>
						<dd class="content_accordion_child_content" >
							 <p>アコーディオン1のコンテンツアコーディオン1のコンテンツ<br>アコーディオン1のコンテンツ</p>
						</dd>
					</dl>
					<dl class="content_accordion_child close" data-accordion="close">
						<dt class="content_accordion_child_index">
							見出し2
							<span class="content_accordion_child_indexCap close">close</span>
							<span class="content_accordion_child_indexCap open">open</span>													
						</dt>
						<dd class="content_accordion_child_content" >
							 <p>アコーディオン2のコンテンツアコーディオン2のコンテンツ<br>アコーディオン2のコンテンツ</p>
						</dd>
					</dl>
					<dl class="content_accordion_child close" data-accordion="close">
						<dt class="content_accordion_child_index">
							見出し3
							<span class="content_accordion_child_indexCap close">close</span>
							<span class="content_accordion_child_indexCap open">open</span>							
						</dt>
						<dd class="content_accordion_child_content" >
							 <p>アコーディオン3のコンテンツアコーディオン3のコンテンツ<br>アコーディオン3のコンテンツ</p>
						</dd>
					</dl>
				</div>
			</section>

	<script type="text/javascript" src="http://satohmsys.info/files/demo/tweenmax/site/js/tweenmax/minified/TweenMax.min.js"></script>
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Pacifico);
body, html {
  padding: 0;
  margin: 0;
}

html {
  position: relative;
  border-top: solid 5px #121212;
  line-height: 1.6;
}

img {
  line-height: 1;
  max-width: 100%;
  height: auto;
  outline: 0;
}

ul {
  margin: 0;
  padding: 0;
}

.content_accordion .section_index {
  display: table;
  text-align: center;
  white-space: nowrap;
}
.content_accordion .section_index:after, .content_accordion .section_index:before {
  content: '';
  display: table-cell;
  width: 50%;
  background: linear-gradient(rgba(0, 0, 0, 0) 50%, currentColor 50%, currentColor calc(50% + 1px), rgba(0, 0, 0, 0) calc(50% + 1px));
  background-clip: padding-box;
}
.content_accordion .section_index:after {
  border-left: 1em solid transparent;
}
.content_accordion .section_index:before {
  border-right: 1em solid transparent;
}
.content_accordion .section_index {
  font-size: 1em;
  font-weight: normal;
}
.content_accordion .section_content {
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-justify-content: space-around;
      -ms-flex-pack: distribute;
          justify-content: space-around;
  -webkit-align-content: start;
      -ms-flex-line-pack: start;
          align-content: start;
}
.content_accordion_child {
  -webkit-flex-basis: 30%;
      -ms-flex-preferred-size: 30%;
          flex-basis: 30%;
}
.content_accordion_child.close .content_accordion_child_content {
  height: 0;
  display: none;
}
.content_accordion_child_index, .content_accordion_child_content p {
  padding: 1em;
}
.content_accordion_child_index {
  line-height: 1;
  position: relative;
  text-align: center;
  background-color: #eee;
}
.content_accordion_child_indexCap {
  height: 1em;
  margin: auto;
  padding: 0.5em;
  cursor: pointer;
  transition: all 0.5s;
  opacity: 1;
  position: absolute;
  top: 0;
  right: 5px;
  bottom: 0;
  font-size: 0.6em;
  color: #fff;
  border-radius: 3px;
  background-color: #999;
}
.content_accordion_child_indexCap.open {
  background-color: #666;
}
.content_accordion_child_content {
  border: solid 1px #eee;
  margin-left: 0;
}
.content_accordion [data-accordion="open"] .open {
  opacity: 0;
}
.content_accordion [data-accordion="open"] .close {
  opacity: 1;
}
.content_accordion [data-accordion="close"] .open {
  opacity: 1;
}
.content_accordion [data-accordion="close"] .close {
  opacity: 0;
}
@media screen and (max-width: 600px) {
  .content_accordion .section_content {
    -webkit-flex-direction: column;
        -ms-flex-direction: column;
            flex-direction: column;
  }
}
            
          
!
            
              var getByClass = function( cls, num ){
	if( typeof num == "number" ){
		classCollection = document.getElementsByClassName( cls )[num];
	} else {
		classCollection = document.getElementsByClassName( cls );
		classCollection.length == 1 ? classCollection = classCollection[0] : '';

	}
	return classCollection;
};

$accordion = getByClass( 'content_accordion_child' ),
$accordion_tab = getByClass( 'content_accordion_child_index' ),
$TimelineMax = new TimelineMax();


/**
* アコーディオン
*/

Array.prototype.forEach.call( $accordion, function( e, index ){
	var $index =  e.getElementsByClassName( 'content_accordion_child_index' );

	$index[0].addEventListener( 'click', function( e ){
		var $text = e.target;
		
		if( /indexCap/.test( $text.className ) ){
			$parent = $text.parentNode,
			$dd = $parent.nextElementSibling,
			$dtHeight = $parent.clientHeight;
		} else {
			$dd = $text.nextElementSibling,
			$dtHeight = $text.clientHeight;
		}
		$dl = $dd.parentNode,
		$status = $dl.getAttribute('data-accordion');

		//open時=閉じる
		if( $status == 'open' ){		
			$TimelineMax.fromTo( $dd, 0.5, {
				overflow: 'hidden',
			},
			{
				height: 0,
				display: 'none',
				ease:Back.easeIn,
				onComplete: function( ){
					$dl.setAttribute( 'data-accordion', 'close' );
				}
			});
		} else {
			//close時=開く
			
			$TimelineMax.fromTo( $dd, 1, {
				display: 'block',
				overflow: 'hidden'
			},
			{
				height: '80%',
				delay: 0.5,
				ease:Bounce.easeOut,
				onComplete: function(){
					$dl.setAttribute( 'data-accordion', 'open' );
				}
			});		
		}
		
	} );
} );
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console