carousel

In this example below you will see how to do a carousel with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by JunkiSuzuki, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright JunkiSuzuki ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>carousel</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

   <div class="page_contents">
  <div class="program_guide_wrapper">
      <div class="left"><</div> 
      <div class="right">></div>
    <div class="program_guide">
      <div class="time">
        <p>時間1</p>
      </div>
      <div class="program">
        <div class="program_detail_current">
          <div class="program_nav_img">
            <a href="#"><img src="http://pq.qvc.jp/_c_8/634731.jpg" alt=""></a>
          </div>
          <div class="on_air">
            <a href="#"><img src="onair.jpg" alt=""></a>
          </div>
        </div><!-- program_detail_current -->
        
        <div class="program_detail">
          <div class="program_detail_product">
            <div class="program_category">
              <p>カテゴリ</p>
            </div>
            <div class="program_title">
              <p>番組名番組名番組名番組名番組名番組名番組名番組名</p>
            </div>
          </div><!-- program_detail_product -->
          <div class="program_nav_name">
            <p>ナビゲータ名</p>
          </div>
          <div class="program_product_link">
            <a href="#"><img src="onair.jpg" alt=""></a>
          </div>
        </div><!-- program_detail -->
      </div><!-- program --> 
    </div><!-- program_guide  --> 

    <div class="program_guide">
      <div class="time">
        <p>時間2</p>
      </div>
      <div class="program">
        <div class="program_detail_current">
          <div class="program_nav_img">
            <a href="#"><img src="http://pq.qvc.jp/_c_8/634731.jpg" alt=""></a>
          </div>
          <div class="on_air">
            <a href="#"><img src="onair.jpg" alt=""></a>
          </div>
        </div><!-- program_detail_current -->
        
        <div class="program_detail">
          <div class="program_detail_product">
            <div class="program_category">
              <p>カテゴリ</p>
            </div>
            <div class="program_title">
              <p>番組名番組名番組名番組名番組名番組名番組名番組名</p>
            </div>
          </div><!-- program_detail_product -->
          <div class="program_nav_name">
            <p>ナビゲータ名</p>
          </div>
          <div class="program_product_link">
            <a href="#"><img src="onair.jpg" alt=""></a>
          </div>
        </div><!-- program_detail -->
      </div><!-- program --> 
    </div><!-- program_guide  --> 
    
    <div class="program_guide current now">
      <div class="time">
        <p>時間3</p>
      </div>
      <div class="program">
        <div class="program_detail_current">
          <div class="program_nav_img">
            <a href="#"><img src="http://pq.qvc.jp/_c_8/634731.jpg" alt=""></a>
          </div>
          <div class="on_air">
            <a href="#"><img src="onair.jpg" alt=""></a>
          </div>
        </div><!-- program_detail_current -->
        
        <div class="program_detail">
          <div class="program_detail_product">
            <div class="program_category">
              <p>カテゴリ</p>
            </div>
            <div class="program_title">
              <p>番組名番組名番組名番組名番組名番組名番組名番組名</p>
            </div>
          </div><!-- program_detail_product -->
          <div class="program_nav_name">
            <p>ナビゲータ名</p>
          </div>
          <div class="program_product_link">
            <a href="#"><img src="onair.jpg" alt=""></a>
          </div>
        </div><!-- program_detail -->
      </div><!-- program --> 
    </div><!-- program_guide current --> 
    
            <div class="program_guide">
      <div class="time">
        <p>時間4</p>
      </div>
      <div class="program">
        <div class="program_detail_current">
          <div class="program_nav_img">
            <a href="#"><img src="http://pq.qvc.jp/_c_8/634731.jpg" alt=""></a>
          </div>
          <div class="on_air">
            <a href="#"><img src="onair.jpg" alt=""></a>
          </div>
        </div><!-- program_detail_current -->
        
        <div class="program_detail">
          <div class="program_detail_product">
            <div class="program_category">
              <p>カテゴリ</p>
            </div>
            <div class="program_title">
              <p>番組名番組名番組名番組名番組名番組名番組名番組名</p>
            </div>
          </div><!-- program_detail_product -->
          <div class="program_nav_name">
            <p>ナビゲータ名</p>
          </div>
          <div class="program_product_link">
            <a href="#"><img src="onair.jpg" alt=""></a>
          </div>
        </div><!-- program_detail -->
      </div><!-- program --> 
    </div><!-- program_guide  --> 
    
    <div class="program_guide">
      <div class="time">
        <p>時間5</p>
      </div>
      <div class="program">
        <div class="program_detail_current">
          <div class="program_nav_img">
            <a href="#"><img src="http://pq.qvc.jp/_c_8/634731.jpg" alt=""></a>
          </div>
          <div class="on_air">
            <a href="#"><img src="onair.jpg" alt=""></a>
          </div>
        </div><!-- program_detail_current -->
        
        <div class="program_detail">
          <div class="program_detail_product">
            <div class="program_category">
              <p>カテゴリ</p>
            </div>
            <div class="program_title">
              <p>番組名番組名番組名番組名番組名番組名番組名番組名</p>
            </div>
          </div><!-- program_detail_product -->
          <div class="program_nav_name">
            <p>ナビゲータ名</p>
          </div>
          <div class="program_product_link">
            <a href="#"><img src="onair.jpg" alt=""></a>
          </div>
        </div><!-- program_detail -->
      </div><!-- program --> 
    </div><!-- program_guide  --> 
  </div><!-- program_guide_wrapper -->
</div>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/JunkiSuzuki/carousel-PmRvyP */
/*
html5doctor.com Reset Stylesheet
v1.4
2009-07-27
Author: Richard Clark - http://richclarkdesign.com
*/

html, body, div, span, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
abbr, address, cite, code,
del, dfn, em, img, ins, kbd, q, samp,
small, strong, sub, sup, var,
b, i,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, dialog, figure, footer, header,
hgroup, menu, nav, section,
time, mark, audio, video {
	margin:0;
	padding:0;
	border:0;
	outline:0;
	font-size:100%;
	vertical-align:baseline;
	background:transparent;
}

body {
	line-height:1;
}

article, aside, dialog, figure, footer, header,
hgroup, nav, section {
	display:block;
}

nav ul {
	list-style:none;
}

blockquote, q {
	quotes:none;
}

blockquote:before, blockquote:after,
q:before, q:after {
	content:'';
	content:none;
}

a {
	margin:0;
	padding:0;
	border:0;
	font-size:100%;
	vertical-align:baseline;
	background:transparent;
}

ins {
	background-color:#ff9;
	color:#000;
	text-decoration:none;
}

mark {
	background-color:#ff9;
	color:#000;
	font-style:italic;
	font-weight:bold;
}

del {
	text-decoration: line-through;
}

abbr[title], dfn[title] {
	border-bottom:1px dotted #000;
	cursor:help;
}

table {
	border-collapse:collapse;
	border-spacing:0;
}

hr {
    display: block;
    height: 1px;
    border: 0;
    border-top: 1px solid #cccccc;
    margin: 1em 0;
    padding: 0;
}

input, select {
	vertical-align: middle;
}

body {
  -webkit-text-size-adjust: 100%;
}

button {
  background-color: transparent;
  border: none;
  cursor: pointer;
  outline: none;
  padding: 0;
  appearance: none;
}

.page_contents {
  width: 100%;
  max-width: 100%;
  display: block;
  box-sizing: border-box;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  -ms-box-sizing: border-box;
}

.recommend_slider_wrapper {
  width:  80%;
  height: 110px;
  margin : 0 auto;
}

.recommend_slider_flipsnap {
  display: flex;
  justify-content: center;
  margin: 0 auto;
  width: 100%;
  min-width: 640px;
  height: 100px;
  padding: 5px 0 5px 0;
  background: #CCC;
  -webkit-overflow-scrolling: touch;
} 

.recommend_slider_wrapper::-webkit-scrollbar {
  display: none;
}

.recommend_product {
  width: 100px;
  height: 100px;
  margin: 0 3px 0 3px;
  background: #EFEFEF;
}

/* ---------------------------------------------------------------------------- */

.program_guide_wrapper {
  display: flex;
  justify-content: center;
  width: 100%;
  min-width: 640px;
  height: 168px; 
}

.left {
  position: absolute;
  top: 84px;
  left: 10px;
}

.right {
  position: absolute;
  top: 84px;
  right: 10px;
}

.program_guide {
  width: 203px;
  height: 100%; 
  background: #ccc;
}

.program_guide .time {
  height: 35px;
  background: #ccc;
}

.current {
  width: 252px;
  height: 100%; 
}

.current .time {
  background: pink;
}

.program {
  display: flex;
  width: 100%;
  height: 100%;
} 

.program_detail_current {
  display: none;
} 

.current .program_detail_current {
  display: block;
} 

.current .time {
  background: pink;
}

.program_nav_img img{
  width: 50px;
  height: 50px;
}

.on_air img{
  width: 48px;
  height: 19px;
  background: white;
}
 
.program_detail_product {
  width: 100%;
  height: 50px;
  margin: 1px;
  opacity: 100%;
  color: #4a4a4a;
  font-size: 14px;
  font-face: Meiryo;
  line: 17px;
}

.program_nav_name {
  opacity: 100%;
  color: #4a4a4a;
  font-size: 14px;
  font-face: Meiryo;
  line: 17px;
}

.program_product_link img{
  width: 120px;
  height: 19px;
  background: white;
}





/*Downloaded from https://www.codeseek.co/JunkiSuzuki/carousel-PmRvyP */
$(function() {
 $(".right").click(function() {
   var width = $(".now").width();
   var marginLeft =  $(".program_guide_wrapper").css('margin-left');
   var moveWidth = parseInt(width) + parseInt(marginLeft);
   $(".program_guide_wrapper").animate({
     'marginLeft': moveWidth
   });
   var index = $('.now').index('.program_guide');   
$('.program_guide').eq(index - 1).addClass("now");
$('.program_guide').eq(index).removeClass("now");
 }); 
});

Comments