Pen Settings

HTML

CSS

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

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

              
                <div class="controlls">
    <textarea id="topic"></textarea>
  <button class="topicSubmit">Submit</button>
</div>

<div class="collageBox">
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
  <div class="collageBox__item"></div>
</div>


              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
}

.controlls {
  position: fixed;
  top: 0;
  z-index: 100;
  width: 100%;
  margin: auto;
  background-color: rgba(23, 23, 23, 1);
  padding: 2rem 100px;
  box-shadow: 0 5px 15px rgba(0,0,0,0.3);

  textarea {
    width: 100%;
    padding: 10px;
    height: 40px;
  }
}

.collageBox {
  width: 500px;
  margin: 300px auto;
  display: flex;
  flex-wrap: wrap;
  transition: ease 0.4s;
  
  &:hover {
    width: 70%;
  }
  
  &__item {
    padding-bottom: 16%;
    background: #f1f1f1;
    background: transparent;
    width: 16%;
    margin: 0.3333%;
    position: relative;
  }
  
  &__unsplash { 
       transition: ease 3.4s;
       transform: translateY(-100px);
      
    img {
      position: absolute;
      z-index: 1;
      left: 150%;
      transform: translateX(-100%);
      top: 0;
      bottom: 0;
      margin: auto;
      
      &:hover {
        opacity: 0.7;
      }
      
    }
    
  }
  
  &__one {
    img {
      &:not(:nth-of-type(1)) {
        display: none;
      }
    }
  }
  
    &__two {
    img {
      &:not(:nth-of-type(2)) {
        display: none;
      }
    }
  }
  
  &__three {
    img {
      &:not(:nth-of-type(3)) {
        display: none;
      }
    }
  }
  
    &__four {
    img {
      &:not(:nth-of-type(4)) {
        display: none;
      }
    }
  }
  
  &__five {
    img {
      &:not(:nth-of-type(5)) {
        display: none;
      }
    }
  }
  
  &__six {
    img {
      &:not(:nth-of-type(6)) {
        display: none;
      }
    }
  }
  
  &--sepia {
    filter: sepia(100%);
  }
  
  &--saturate {
    filter: saturate(3);
  }
  
  &--hue {
    filter: hue-rotate(180deg);
  }
}


.topicSubmit {
  
  &--done {
    pointer-events: none;
    opacity: 0.5;
  }
}
              
            
!

JS

              
                // unsplash source https://source.unsplash.com/1600x900/?beach
// $( ".collageBox__unsplash" ).append( "<img src='"+url+"'/>" );
//https://api.datamuse.com/words?ml=

  // add this for plugging in input
  // $(".topicSubmit").on("click", function() {
  //   var topicInput = $("#topic").val();
  //   linkDatamuse = "https://api.datamuse.com/words?ml=beach&max=10";
  //   linkDatamuse = "https://api.datamuse.com/words?ml=" + topicInput + "&max=10";
  // })

 $(".topicSubmit").on("click", function() {
  
   $(this).addClass("topicSubmit--done"); 
   
  var $log = console.log
  
  // FILTER
  var photoCount = $('.collageBox__unsplash').length;
  var filter = {};
     
  // DATAMUSE
  var words = [];  
  var word = {};
  var topicInput = $("#topic").val();
//  var linkDatamuse = "https://api.datamuse.com/words?ml=beach&max=10";
  var linkDatamuse = "https://api.datamuse.com/words?ml=" + topicInput + "&max=10"; 
  
   
   
   
  function unsplash() {
    // adds unsplash class to random items in the grid
    var randomNumber = Math.ceil(Math.random() * 35) + 1
    var itemPicker = ".collageBox__item:nth-of-type(" + randomNumber + ")";        
    $(itemPicker).addClass('collageBox__unsplash')
  } 
  
  function photoFilter() {
    // adds photo filter to random items in the grid
    var filters = Array("collageBox--sepia","collageBox--saturate","collageBox--hue","none","none","none");
    filter = filters[Math.floor(Math.random()*filters.length)];
  }; 

   
  [1,2,3,4,5,6].forEach(function(i) {
    unsplash(); 
  });
   
        
  $('.collageBox__unsplash').each(function(photoCount){
    if(photoCount == 0)$(this).addClass("collageBox__one");
    if(photoCount == 1)$(this).addClass("collageBox__two");
    if(photoCount == 2)$(this).addClass("collageBox__three");
    if(photoCount == 3)$(this).addClass("collageBox__four");
    if(photoCount == 4)$(this).addClass("collageBox__five");
    if(photoCount == 5)$(this).addClass("collageBox__six");
  });
  
    $('.collageBox__unsplash').each(function(i, obj) {
      
      photoFilter();
      $(this).addClass(filter);
      
      // SIZE
      var widths = Array(200,256,320,410,470,500);
      var width = widths[Math.floor(Math.random()*widths.length)];
      var height = width / 1.6;
      
    
      
      // URL BULID
      var url = "https://source.unsplash.com/"+width+"x"+height+"/?";      
      // TOPIC ~ DATAMUSE
      $.getJSON(linkDatamuse, function (data) {
        data.forEach(function(element){
          words.push(url+element.word);
        })        
        url = words[Math.floor(Math.random()*words.length)];
 
        $('.collageBox__unsplash').append( "<img src='"+url+"'/>" );
      });
  });
   
   $(".collageBox__unsplash").on("click", function() {
     $("img", this).css("display","none");
   });
});


// $(document).ready(function() {  

//   if ($('.collageBox__unsplash img')) {
//     console.log("ok") 
//   } else {
//     console.log("no way") 
//   }

//   $('.collageBox__unsplash').css("background","red");

// });



//             // OLD DATAMUSE - DIDN'T WORK
//             function getDatamuse(word) {
//               var textareaInput = $("#forDatamuse").val();
//               //  var linkDatamuse = "https://api.datamuse.com/words?ml=" + textareaInput + "&max=10";
//               var linkDatamuse = "https://api.datamuse.com/words?ml=beach&max=10";
//               $.getJSON(linkDatamuse, function (data) {
//                 data.forEach(function(element){

//                   var url = $(".collageBox__unsplash img").attr("src");
//                   url = url.substring(0, url.indexOf('?'));
//                   url = url + element.word;     
//                   $log(url)  
//                 })        
//               });
//             }
//             getDatamuse();


              
            
!
999px

Console