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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <body>

  <h1></h1>
  <div class="giphy">
    <a href="https://giphy.com/" target="blank">
        <img src="https://tctechcrunch2011.files.wordpress.com/2016/02/giphyseriesc.gif?w=738" alt="giphy">
        </a>
  </div>
  <p><img id="gif" src="" ></p>
  <div class="field tabs">
    <input id="search" placeholder="Search for a gif">
    <button id="btn" onclick="getGiphyData()">Search</button>
    <button id="btn" onclick="getTrendingData()">Trending</button>
    <button id="btn1" onclick="getFavoritesData()">Favorites</button>
     
  
    
    <div id="tenGifs">
    </div>

   
    
    
    
    
    
   <footer>
  <p>Dakota Coleman 2018</p>
</footer>

</body>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 10;
  box-sizing: border-box;
}

body {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-family: Arial;
  text-align: center;
  min-height: 50vh;
  min-width: 370px;
  background-color: #18181A;
  background-size: 200%;
}

h1 {
  padding: 20px 10px;
  letter-spacing: 0.2em;
  color: white;
}

field * {
  background: rgba(256, 256, 256, 0.3);
  color: white;
}

#btn {
  padding: 10px;
  border-radius: 2px;
  font-size: 16px;
  border: 2px solid white;
}

#btn1 {
  padding: 10px;
  border-radius: 2px;
  font-size: 16px;
  border: 2px solid white;
}

tab:focus {
  display:flex;
}


::placeholder {
  color: #f5f5f5;
}

#search {
  padding: 11px;
  width: 40%;
  min-width: 200px;
  max-width: 400px;
  border: 2px solid white ;
}

#search {
  outline: 0;
  color: #333;
  background: white;
  box-shadow: 0 0 1px 1px rgba(0, 0, 0, 0.3);
}

#btn {
  cursor: pointer;
  width: 90px;
}


giphy {
  padding: 20px 0px 15px 0;
}

giphy img {
  width: 500px;
  max-width: 800px;
  margin: auto;
  display: block;
}

giphy img.gif {
  width: 100%;
  max-width: 600px;
  box-shadow: 0 0 1px 1px rgba(256, 256, 256, 0.3);
}

footer {
  padding: 5px;
  font-size: 14px;
  color: white;
}

footer a {
  color: #333;
  text-decoration: none;
}
footer a:hover {
  color: white;
  text-decoration: underline;
}


              
            
!

JS

              
                function getGiphyData() {
  //Get giphy data
  var searchTerm = document.querySelector("#search").value;
  var url =
    "https://api.giphy.com/v1/gifs/search?api_key=wOkuLOpg0lyr0TN1NMtr0qIAsJpFW7rn&q=" +
    searchTerm;

  fetch(url)
    .then(data => data.json())
    .then(res => {
      console.log(res);

      var arrayOfGifs = res.data;
      var rand = Math.floor(Math.random() * arrayOfGifs.length);
      var firstItem = arrayOfGifs[rand];
      var giphyLink = firstItem.images.fixed_width.url;
      //makes giphy appear on page
      document.querySelector("#gif").setAttribute("src", giphyLink);
    })
    .catch(error => console.log(error));
}

function getTrendingData() {
  var url =
    "https://api.giphy.com/v1/gifs/trending?api_key=wOkuLOpg0lyr0TN1NMtr0qIAsJpFW7rn&q";

  fetch(url)
    .then(data => data.json())
    .then(res => {
      console.log(res);
      var _outputHTML = "";
      var _tenGifs = document.getElementById("tenGifs");
      //  document.querySelector("#gif1").setAttribute("src", giphyLink);
      if (res.data.length < 10) return; // if not ten quit for now
      for (let i = 0; i < 10; i++) {
        // add 10 gifs by appending new elements to the div #tenGifs
        var node = document.createElement("img");
        node.setAttribute("src", res.data[i].images.fixed_width.url);
        _tenGifs.appendChild(node);
      }

    
    });
}
 function setFavorite(imgId) {
   
 }
              
            
!
999px

Console