Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!-- 
This game is on iOS and Android "Infinity Loop"
I loved the concept ant wanted to see if I could make it in jQuery 
-->
<div id="toolbar"><span id="theme">Light Off</span><span class="toggleCreateLevel"> Create Level</span> <span class="link">Inspired by <a href="http://loopgame.co/" target="_blank">loopgame.co</a></span></div>

<div class="level1" data-code="1231243" data-set="e1.b.c2.c3.c1.s2.c4.e2" data-text="Rotation Game <br><span>Click a block to complete the pipe.</span>"></div>
<div class="level2" data-code="2323114311231414" data-set="c1.c2.c4.c1.s2.c3.c1.e1.s1.e2.c1.c3.c4.c1.c2.c3"></div>
<div class="level3" data-code="42232324114122322243" data-set="e2.s1.s2.c2.c2.c1.c1.c1.s2.c2.c2.b.c2.s2.s2.c1.c1.s1.s1.c1.e2.b.b.b"></div>
<div class="level4" data-code="2222423124111111414" data-set="b.c1.s1.e1.c1.c1.c1.c2.s2.c2.c2.s2.s2.s1.e2.s1.c2.c1.c2.c2"></div>
<div class="level5" data-code="222314311113443" data-set="c2.s1.s2.c1.s2.e1.c1.s1.s1.b.s2.s2.e1.e1.c1.e1" data-text="Multiple pipes."></div>
<div class="level6" data-code="112413123111111414" data-set="b.e1.e2.b.c2.c1.c1.c1.s1.c1.c1.s2.s1.s2.s2.s1.c2.c1.c1.c2"></div>
<div class="level7" data-code="2323141423231414" data-set="c4.c1.c3.c1.c2.c3.c4.c1.c2.c1.c3.c2.c1.c1.c2.c1" data-text="Circles."></div>
<div class="level8" data-code="222312242211314311143" data-set="c4.s1.s1.c1.c2.s2.s2.c1.b.c2.e3.e4.b.c2.c1.s2.e3.c2.s2.s1.b.c1.c2.e1"></div>
<div class="level9" data-code="222244312241123132414" data-set="b.c1.s1.e2.c2.c2.e1.c2.s1.c2.s2.c1.s1.c1.s1.c2.c1.c2.c2.c2.b.c2.c1.b"></div>
<div class="level10" data-code="122311241413422423311231223" data-set="e1.c2.s1.c4.s1.s2.c1.c3.c1.c3.c2.c4.e2.e4.c3.c2.c4.c2.e4.b.s1.c3.s2.c4.c1.s1.e2.e3"></div>
<div class="level11" data-code="432224131431121122331222" data-set="e1.c2.c1.e1.c1.c1.c1.c1.s1.e1.c2.s1.c1.e2.s2.s2.c1.e1.e1.e1.c2.s1.s2.e1"></div>
<div class="level12" data-code="42232224122311113441222" data-set="e2.s1.s2.c1.c2.s2.s1.c2.s2.c1.s2.c2.s1.s2.b.s2.s2.e2.e2.c1.c1.s2.s2.e1"></div>
<div class="level13" data-code="2221223144422231241424" data-set="c1.s1.e1.b.s2.c1.s2.c1.c1.c1.e2.c2.c1.e2.c1.c2.c2.s2.c2.s2.b.e1.s2.c1"></div>
<div class="level14" data-code="1231141442314314442333" data-set="e1.c2.c1.e2.c1.c2.c2.c2.e1.s2.c2.e1.e1.c1.c2.c1.e1.c2.c2.c2.b.b.e1.e2"></div>
<div class="level15" data-code="1223113112434323111111411224" data-set="e1.c2.s1.c2.s2.c1.c1.s2.c2.s2.c1.e1.e1.c1.c2.c1.e1.s1.s2.s2.s1.c1.c1.s2.c1.s2.s2.c1"></div>
<div class="level16" data-code="422122243123241112414224" data-set="e2.s1.e2.e1.c1.s1.s1.c2.e2.e2.c2.c1.c1.c2.s1.s2.c1.s1.c1.s2.e1.s1.s2.c1"></div>

<div id="win"><div class="text">Level <span>1</span> Complete</div></div>
<div id="finished"><div class="text">Game Completed!</div></div>

<div id="createLevel">
  <div class="newLevel"></div>
  <div class="stats"></div>
  <div class="tools">
    <img src="https://db.tt/k4C8HDzW" alt="" class="curve" />
    <img src="https://db.tt/q7awJWNW" alt="" class="straight" />
    <img src="https://db.tt/gBByua2j" alt="" class="end" />
    <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" alt="" class="bnone" />
  </div>
</div>
              
            
!

CSS

              
                body {
  font-family:'Source Sans Pro', 'Helvetica Neue';
  font-size:16px;
  background:#000;
  color:#fff;
}
body.light {
  background:#fff;
  color:#111;
}
#toolbar {
  position:fixed;
  top:0;
  left:0;
  width:100%;
  line-height:25px;
  padding:10px;
  box-sizing:border-box;
  transition:0.15s;
  opacity:0;
  z-index:999999999;
  animation:3s toolbar ease-in-out;
}
#toolbar:hover {
  opacity:1;
}
@keyframes "toolbar" {
  0%,50%{opacity:1}
}
#theme {
  padding-right:15px;
  float:left;
}
#toolbar .link{
  float:right;
}
#toolbar a {
  color:inherit;
  text-decoration:none;
}
#win,
#finished{
  position:fixed;
  top:0;
  left:0;
  width:100%;
  height:100%;
  background:inherit;
  color:inherit;
  z-index:9999;
  display:none;
}
#win .text,
#finished .text {
  position:absolute;
  top:50%;
  left:50%;
  font-size:40px;
  font-weight:100;
  transform:translate3d(-50%,-50%,0);
}
body.light #win .text,
body.light #finished .text {
  color:#111!important;
}
div[class^="level"] {
  position:fixed;
  top:50%;
  left:50%;
  width:280px;
  transform:translate3d(-50%,-50%,0);
  display:none;
}
div[class^="level"] .text {
  font-size:19px;
  padding-top:20px;
  clear:both;
  overflow:hidden;
}
div[class^="level"] .text span {
  padding:10px 0 0;
  font-size:15px;
  display:block;
}
div[class^="level"] .text.center {
  text-align:center;
}
div[class^="level"] .block,
#createLevel .newLevel .block {
  position:relative;
  width:70px;
  height:70px;
  float:left;
  cursor:pointer;
  overflow:hidden;
  transition:0.15s ease-in-out;
}
div[class^="level"] .block.curve:before,
#createLevel .newLevel .block.curve:before {
  position:absolute;
  top:0;
  left:0;
  width:70px;
  height:70px;
  background:url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/363972/curve.png) 50% 50% / contain no-repeat;
  display:block;
  content:'';
}
div[class^="level"] .block.curve.double:before,
#createLevel .newLevel .block.curve.double:before {
  background:url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/363972/curve-double.png) 50% 50% / contain no-repeat;
}
div[class^="level"] .block.straight:before,
#createLevel .newLevel .block.straight:before {
  position:absolute;
  top:0;
  left:0;
  width:70px;
  height:70px;
  background:url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/363972/straight.png) 50% 50% / contain no-repeat;
  display:block;
  content:'';
}
div[class^="level"] .block.straight.double:before,
#createLevel .newLevel .block.straight.double:before {
  background:url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/363972/straight-double.png) 50% 50% / contain no-repeat;
}
div[class^="level"] .block.end:before,
#createLevel .newLevel .block.end:before {
  position:absolute;
  top:0;
  left:0;
  width:70px;
  height:70px;
  background:url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/363972/end.png) 50% 50% / contain no-repeat;
  display:block;
  content:'';
}

body.light div[class^="level"] .block,
body.light #createLevel .newLevel .block {
  -webkit-filter: invert(1);
   filter: invert(1);
}
div[class^="level"] .block.r1,
#createLevel .newLevel .block.r1{
  transform:rotate(0deg);
}
div[class^="level"] .block.r2,
#createLevel .newLevel .block.r2{
  transform:rotate(90deg);
}
div[class^="level"] .block.r3,
#createLevel .newLevel .block.r3{
  transform:rotate(180deg);
}
div[class^="level"] .block.r4,
#createLevel .newLevel .block.r4{
  transform:rotate(270deg);
}

#createLevel {
  position:fixed;
  top:0;
  left:0;
  width:100%;
  height:100%;
  background:inherit;
  color:inherit;
  z-index:99999;
  display:none;
}
#createLevel .newLevel {
  position:absolute;
  top:50%;
  left:50%;
  width:280px;
  transform:translate3d(-50%,-50%,0);
}
#createLevel .newLevel .block {
  border: 1px solid #fff;
  box-sizing: border-box;
}
#createLevel .stats {
  position:absolute;
  bottom:80px;
  width:100%;
  height:25px;
  line-height:25px;
  text-align:center;
}
#createLevel .tools {
  position:absolute;
  bottom:0;
  left:50%;
  width:280px;
  height:80px;
  transform:translate3d(-50%,0,0);
}
body.light #createLevel .tools {
  -webkit-filter: invert(1);
   filter: invert(1);
}
#createLevel .tools img {
  margin:10px;
  width:50px;
  height:50px;
  float:left;
  border:2px solid #fff;
  box-sizing:border-box;
  cursor:pointer;
  display:block;
}
              
            
!

JS

              
                (function(){
  var stage = 1,
      active = 1,
      levelCount = $('div[class^=level]').length,
      createLevelState = 0;
  setTheme();
  createLevels();
  showLevels();
  
  $('body').on('click','.block',function(){
    var x = $(this).attr('class').replace(/\D+/g,'');
    if(active && x){
      $(this).removeClass('r' + x);
      x++;
      if($(this).hasClass('straight')){
        if(x == 3) x = 1;
      }else if(x == 5){
        x = 1;
      }
      $(this).addClass('r' + x);
      if(!createLevelState){
        combination();
      }else{
        levelStats();
      }
    }
  });
  
  //d
  
  $('#theme').click(function(){
    $('body').toggleClass('light');
    if($('body').attr('class') == 'light') {
      $('#theme').text('Lights Off');
    }else{
      $('#theme').text('Lights On');
    }
    localStorage.setItem('theme', $('body').attr('class'));
  });
  
  function combination() {
    var x = $('.level' + stage).find('.block'), h = '';
    $.each(x, function(i, el) {
      h += $(this).attr('class').replace(/\D+/g,'');
    });
    console.info(h);
    if($('.level' + stage).data('code') == h){
      stage++;
      active = 0;
      setTimeout(function(){
        showLevels();
      },500);
    }
  }
  
  function showLevels() {
    var remove = stage - 1;
    $('#win .text span').text(remove);
    if(stage > levelCount){
      $('#finished').fadeIn();
    }else if(stage > 1){
      $('#win').fadeIn();
      setTimeout(function(){
        $('.level' + remove).remove();
        $('div.level' + stage).show();
        $('#win').fadeOut();
        active = 1;
      },2000);
    }else{
      $('div.level' + stage).fadeIn();
    }
  }
  
  function createLevels() {
    $.each($('div[data-set]'), function(i,el){
      var levelHtml = '';
      var set = $(this).data('set').split('.');
      $.each(set, function(i, el) {
        var style = 'curve';
        if(set[i][0] == 's') style = 'straight';
        if(set[i][0] == 'e') style = 'end';
        if(set[i][0] == 'b') style = '';
        var rotate = ''
        if(set[i][1]) var rotate = 'r' + set[i][1];
        var double = ''
        if(set[i][2]) var double = 'double';
        levelHtml += '<div class="block ' + style + ' ' + double + ' ' + rotate + '"></div>';
      });
      var text = $(this).data('text');
      if(text) levelHtml += '<div class="text">'+text+'</span></div>';
      $(this).append(levelHtml);
    });
  }
  
  function setTheme() {
    if(localStorage.theme == 'light') {
      $('body').addClass('light');
      $('#theme').text('Lights Off');
    }
  }
  
  function levelStats() {
    var code = '', set = '';
    $.each($('.newLevel .block'),function(i, el){
      var s = $(this).attr('class').split(' ')[1][0];
      if(s != 'b') code += $(this).attr('class').replace(/\D+/g,'');
      var r = Math.floor(Math.random() * 2) + 1;
      if(s != 's') Math.floor(Math.random() * 4) + 1;
      if(s == 'b') r = '';
      set +=  s + r + '.';
    });
    set = set.slice(0, -1);
    $('.stats').html('code: ' + code + ' - Set: ' + set);
  }
  
  $('.toggleCreateLevel').click(function(){
    $('#createLevel .newLevel').empty();
    $('#createLevel').fadeToggle();
    if(!createLevelState){
      createLevelState = 1;
    }else{
      createLevelState = 0;
    }
  });
  
  $('.tools img').click(function(){
    var x = $(this).attr('class');
    $('.newLevel').append('<div class="block ' + x + ' r1"></div>');
  });
})();
              
            
!
999px

Console