cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

            
              <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="car">
  <div class="container">
    <div class="changeCarSelect">
      <span>Change Car</span>
      <select class="selectContainer">
        <option class="selectCar" data-index="1">
          Blue car
        </option>
        <option class="selectCar" data-index="2">
          Red car
        </option>
        <option class="selectCar" data-index="3">
          Silver car
        </option>
      </select>

    </div>
    <div class="car-button">
      <div class="row">
        <div class="col-md-8 col-md-offset-2">
          <div class="row">
            <div class="col-md-2 col-sm-3 col-xs-6">
              <div class="car-model" data-index="1">
                <h3>Blue car</h3>
              </div>
            </div>
            <div class="col-md-2 col-sm-3 col-xs-6">
              <div class="car-model" data-index="2">
                <h3>Red car</h3>
              </div>
            </div>
            <div class="col-md-2 col-sm-3 col-xs-6">
              <div class="car-model" data-index="3">
                <h3>Silver car</h3>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-lg-12">
        <div class="car-relative">
          <div class="car-image-container current">
            <div class="car-image" data-car-index="1">
              <img class="img-responsive" src="http://store6.up-00.com/2017-03/148992727111161.png" alt="" />
              <div class="car__wheel left" style="background-image:url('http://store6.up-00.com/2017-03/148992740561243.png')"></div>
              <div class="car__wheel right" style="background-image:url('http://store6.up-00.com/2017-03/148992740561243.png')"></div>
            </div>
          </div>
          <div class="car-image-container">
            <div class="car-image" data-car-index="2">
              <img class="img-responsive" src="http://store6.up-00.com/2017-03/148992727131353.png" alt="" />
              <div class="car__wheel left" style="background-image:url('http://store6.up-00.com/2017-03/14899275127831.png')"></div>
              <div class="car__wheel right" style="background-image:url('http://store6.up-00.com/2017-03/14899275127831.png')"></div>
            </div>
          </div>
          <div class="car-image-container">
            <div class="car-image" data-car-index="3">
              <img class="img-responsive" src="http://store6.up-00.com/2017-03/148992727151114.png" alt="" />
              <div class="car__wheel left" style="background-image:url('http://store6.up-00.com/2017-03/149030743068171.png')"></div>
              <div class="car__wheel right" style="background-image:url('http://store6.up-00.com/2017-03/149030743068171.png')"></div>
            </div>
          </div>

        </div>
      </div>
    </div>
    <div class="slectWheel">
      <img src="http://store6.up-00.com/2017-03/148992740561243.png" alt="" />
      <img src="http://store6.up-00.com/2017-03/14899275127831.png" alt="" />
      <img src="http://store6.up-00.com/2017-03/148992740580684.png" alt="" />
    </div>
  </div>
</div>
            
          
!
            
              .slectWheel{
  cursor:pointer;
  text-align:center;
  position:fixed;
  bottom:0;
  left:calc(50% - 150px);
}
.slectWheel img{
  display:inline-block;
}
.car-relative{
  max-height:200px;
  overflow-y:hidden;
}
.car{
  padding:40px 0;
}
.changeCarSelect{
  display:none;
  text-align:left;
}
.changeCarSelect span{
  display:inline-block;
  margin-right:4px;
  font-size:14px;
}
.selectContainer {
  width: 200px;
  padding: 10px 5px;
  display:inline-block;
  margin-bottom:30px;
  /*position:absolute;*/
  font-size: 14px;
  border:1px solid rgba(246, 246, 246, 0.89);
  outline:none;
  cursor:pointer;
}
.selectContainer option{
  padding:20px 2px;
}
.car div[class^='col']{
  padding:5px;
}
.car .car-model{
  width:100%;
  margin-bottom:30px;
  cursor:pointer;
}
.car .car-model h3{
  margin:0;
  padding:15px 10px;
  background-color
  color:#333;
  font-family:"Raleway", Arial, Tahoma;
  font-weight:700;
  font-size:18px;
  text-align:center;
}
.car .car-relative{
  position:relative;
  width:100%;
}
.car-image-container{
  position: absolute;
  left: 100%;
  overflow: hidden;
  /*border:1px solid;*/
}
.car-image-container2{
  position: absolute;
  left: 100%;
  overflow: hidden;
  /*border:1px solid;*/
}
.car-image-container img{
  margin:auto;
}
.current{
  position: relative;
  left: 0;
}
/*.current .current{
left: 0;
}*/

.car .car-image .car__wheel{
  width:99px;
  height:100px;
  position:absolute;
  background-repeat:no-repeat;
  background-position:center center;
  background-size:cover;
}
.car .car-image .car__wheel.left{
  background-image:url('http://store6.up-00.com/2017-03/148992740531661.png');
  top: 87px;
  left: 350px;
}
.car .car-image .car__wheel.right{
  background-image:url('http://store6.up-00.com/2017-03/148992740544512.png');
  top: 87px;
  right: 319px;
}
.car--trans-in .car__wheel{
  animation: roll-in 400s ease-out;
}
.car--trans-out .car__wheel{
  animation: roll-out 400s ease-out;
}
.car--trans-in .car-image{
  animation: trans-in 1s ease-out;
  animation-fill-mode: forwards;
  -moz-animation-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1);
  -o-animation-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1);
  -webkit-animation-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1);
  animation-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1);
}
.car--trans-out .car-image{
  animation: trans-out 1s ease-in;
  animation-fill-mode: forwards;
  -moz-animation-timing-function: cubic-bezier(0.895, 0.03, 0.685, 0.22);
  -o-animation-timing-function: cubic-bezier(0.895, 0.03, 0.685, 0.22);
  -webkit-animation-timing-function: cubic-bezier(0.895, 0.03, 0.685, 0.22);
  animation-timing-function: cubic-bezier(0.895, 0.03, 0.685, 0.22);
}
.car--trans-in .car__wheel{
  animation: roll-in 1s ease-out;
  -moz-animation-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1);
  -o-animation-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1);
  -webkit-animation-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1);
  animation-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1);
}
.car--trans-out .car__wheel{
  animation: roll-out 1s ease-out;
  -moz-animation-timing-function: cubic-bezier(0.895, 0.03, 0.685, 0.22);
  -o-animation-timing-function: cubic-bezier(0.895, 0.03, 0.685, 0.22);
  -webkit-animation-timing-function: cubic-bezier(0.895, 0.03, 0.685, 0.22);
  animation-timing-function: cubic-bezier(0.895, 0.03, 0.685, 0.22);
}
.car--trans-in .car-image img {
  -moz-animation: bounce-in 1s ease-out;
  -o-animation: bounce-in 1s ease-out;
  -webkit-animation: bounce-in 1s ease-out;
  animation: bounce-in 1s ease-out;
  -moz-animation-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1);
  -o-animation-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1);
  -webkit-animation-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1);
  animation-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1);
}
.car--trans-out .car-image img {
  animation: bounce-out 1s ease-in;
  -moz-animation-timing-function: cubic-bezier(0.895, 0.03, 0.685, 0.22);
  -o-animation-timing-function: cubic-bezier(0.895, 0.03, 0.685, 0.22);
  -webkit-animation-timing-function: cubic-bezier(0.895, 0.03, 0.685, 0.22);
  animation-timing-function: cubic-bezier(0.895, 0.03, 0.685, 0.22);
}

@keyframes trans-in {
  0% {transform: translateX(150%);}
  80% {transform: translateX(0%);}
  100% {transform: translateX(0%);}
}
@keyframes trans-out {
  0% {transform: translateX(0%);}
  10% {transform: translateX(0%);}
  80% {transform: translateX(-100%);}
  100% {transform: translateX(-100%);}
}
@keyframes roll-in {
  0% {transform: rotate(0deg);}
  80% {transform: rotate(-720deg);}
  100% {transform: rotate(-720deg);}
}
@keyframes roll-out {
  0% {transform: rotate(0deg);}
  100% {transform: rotate(-720deg);}
}
@keyframes bounce-in {
  0% {transform: rotate(0deg);}
  5.67% {transform: rotate(0deg);}
  33% {transform: rotate(-0.5deg);}
  77.52% {transform: rotate(-0.5deg);}
  100% {transform: rotate(0deg);}
}
@keyframes bounce-out {
  0% {transform: rotate(0deg);}
  47.15% {transform: rotate(1deg);}
  100% {transform: rotate(1deg);}
}
/*==============
Responsive Media Query
==============*/
/* ========================
Note3, Note2, SIII, S5, Lumia950, Nexus5, Nokia N9 : 360px * 640px
Iphone6: 375px * 667px
lg optimus l70, Nexus4: 384px * 640px
Nexus6, Nexus5X, Nexus6P: 412px * 732px
Iphone6Plus: 414px * 736px
======================== */
@media only screen and (min-width: 310px) and (max-width:320px) {
  .car .car-image .car__wheel{
    width:46px;
    height:46px;
  }
  .car .car-image .car__wheel.left {
    top: 41px;
    left: 47px;
  }
  .car .car-image .car__wheel.right {
    top:39px;
    right:33px;
  }
}
@media only screen and (min-width: 330px) and (max-width:360px) {
  .car .car-image .car__wheel{
    width:55px;
    height:55px;
  }
  .car .car-image .car__wheel.left {
    top: 44px;
    left: 52px;
  }
  .car .car-image .car__wheel.right {
    top: 44px;
    right: 37px;
  }
}
@media only screen and (min-width: 361px) and (max-width:375px) {
  .car .car-image .car__wheel{
    width:52px;
    height:52px;
  }
  .car .car-image .car__wheel.left {
    top: 48px;
    left: 57px;
  }
  .car .car-image .car__wheel.right {
    top: 48px;
    right: 41px;
  }
}
@media only screen and (min-width: 380px) and (max-width:384px) {
  body{
    background-color:red;
  }
  .car .car-image .car__wheel{
    width:53px;
    height:53px;
  }
  .car .car-image .car__wheel.left {
    top: 50px;
    left: 58px;
  }
  .car .car-image .car__wheel.right {
    top: 50px;
    right: 41px;
  }
}
@media only screen and (min-width: 390px) and (max-width:414px) {

  .car .car-image .car__wheel{
    width:60px;
    height:60px;
  }
  .car .car-image .car__wheel.left {
    top: 52px;
    left: 62px;
  }
  .car .car-image .car__wheel.right {
    top: 52px;
    right: 43px;
  }
}
@media only screen and (min-width: 580px) and (max-width:600px) {
  .car .car-image .car__wheel{
    width:92px;
    height:92px;
  }
  .car .car-image .car__wheel.left {
    top: 77px;
    left: 88px;
  }
  .car .car-image .car__wheel.right {
    top: 77px;
    right: 60px;
  }
}
@media only screen and (min-width: 630px) and (max-width:640px) {
  .car .car-image .car__wheel{
    width:92px;
    height:92px;
  }
  .car .car-image .car__wheel.left {
    top: 84px;
    left: 98px;
  }
  .car .car-image .car__wheel.right {
    top: 84px;
    right: 66px;
  }
}
@media (max-width: 768px){
  .changeCarSelect{
    display:block;
  }
  .car-button{
    display:none;
  }
}
@media (min-width: 768px) and (max-width: 992px){
  .car .car-image .car__wheel.left {
    left:140px;

  }
  .car .car-image .car__wheel.right {
    right: 108px;
  }
}

@media (min-width: 992px) and (max-width: 1200px){
  .car .car-image .car__wheel{

  }
  .car .car-image .car__wheel.left {
    left:250px;
  }
  .car .car-image .car__wheel.right {
    right: 216px;
  }
}
.whelrotateClick .car__wheel{
  animation-name:animation;
  animation-duration:5s;
  animation-iteration-count:infinite;
  animation-timing-function:linear;
}
@keyframes animation {
  from {
    -moz-transform: rotate(0);
    -ms-transform: rotate(0);
    -o-transform: rotate(0);
    -webkit-transform: rotate(0);
    transform: rotate(0);
  }

  to {
    -moz-transform: rotate(-360deg);
    -ms-transform: rotate(-360deg);
    -o-transform: rotate(-360deg);
    -webkit-transform: rotate(-360deg);
    transform: rotate(-360deg);
  }
}
            
          
!
            
              // Get wheels for all cars onload.
// It is an array of object (in case of two wheel model on the same car)
var carWheelArr=[];
$(".car-image").each(function(i){
  var leftWheel = $(this).find(".car__wheel").eq(0).css("background-image");
  var rightWheel = $(this).find(".car__wheel").eq(1).css("background-image");
  carWheelArr[i] = {};
  carWheelArr[i].left=leftWheel;
  carWheelArr[i].right=rightWheel;
});
//console.log(JSON.stringify(carWheelArr));

// Change wheels handler.
$('.slectWheel img').click(function (e) {
  console.log("Select wheel");
  var currentWheel = $('.current .car__wheel').css('background-image');
  e.preventDefault();
  var getImgWheel = $(this).attr('src');
  $(".current").find('.car__wheel').css('background-image','url(' + getImgWheel + ')');
  $('.current').addClass('whelrotateClick');
});

// Change car handler
var $cars = $('.car');
$('.car-model').on('click', function () {

  // Get current car.
  var currentCar=$(document).find(".current");
  // Get its car index (minus one to comply zero based array)
  var currentCarIndex=parseInt($(document).find(".current").children().first().attr("data-car-index"))-1;
  console.log("car#: "+currentCarIndex +" is leaving...");

  // Reset wheels.
  //console.log(carWheelArr[currentCarIndex].left);
  currentCar.find(".left").css({"background-image":carWheelArr[currentCarIndex].left})
  currentCar.find(".right").css({"background-image":carWheelArr[currentCarIndex].right})

  var index = $(this).data('index');
  var $current = $cars.find('.current');
  var $next = $('[data-car-index="' + index + '"]').parent();

  var currentINDEX = $current.children().first().attr("data-car-index");
  var nextINDEX = $next.children().first().attr("data-car-index");


  //console.log(currentINDEX+" "+nextINDEX);

  if( currentINDEX < nextINDEX ){
    console.log("NEXT CAR");
    $next.css({"top":"-200px"});
    $current.addClass('car--trans-out');
    differentcar=true;
  }
  if( currentINDEX > nextINDEX ){
    console.log("PREVIOUS CAR");
    $current.addClass('car--trans-out');
    differentcar=true;
    setTimeout(function(){
      $current.css({"top":"-200px"});
    },350);
  }

  if( currentINDEX == nextINDEX ){
    console.log("SAME CAR!");
    differentcar=false;
    $current.addClass('car--trans-out');

    setTimeout(function(){
      $current.removeClass('car--trans-out').addClass('car--trans-in');
      setTimeout(function(){
        $current.removeClass('car--trans-in');
      },1000);
    },1000);

  }

  // In all cases... Need to clean the top offset
  setTimeout(function(){
    $(".car-image-container").css({"top":"0px"});
  },1000);



  // Next car enters
  if(differentcar){
    setTimeout(function () {
      $next.addClass('current').addClass('car--trans-in');
    },400);

    setTimeout(function () {
      $('.car-image-container').removeClass('whelrotateClick');
      $current.removeClass('current').removeClass('car--trans-out');
      $next.css({"top":"0px"}).removeClass('car--trans-in');
    }, 1000);
  }
});

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console