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

Auto Save

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

              
                
<header>
  <h1>Giphy Search</h1>
  
  <form action="" method="post" autocomplete="off">
    <label for="" style="display: none;">Search</label>
    <input class="search" type="text" name="search" placeholder="Search" required>
    <input class="btn" type="submit" value="OK">
    <input class="btn clear" value="Clear" readonly>
  </form>
</header>

<section>
  <div class="giphy">
    <a href="https://giphy.com/" target="_blank">
      <img src="https://res.cloudinary.com/beumsk/image/upload/v1520544016/giphy-logo-6611-s-_vme7aa.png" alt="giphy">
    </a>
  </div>
</section>

<footer>
  <p>Created by <a href="https://remybeumier.be" target="_blank">Rémy Beumier</a> with <a href="https://developers.giphy.com/docs/" target="_blank">Giphy API</a></p>
</footer>
              
            
!

CSS

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

body {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-family: Arial;
  text-align: center;
  min-height: 100vh;
  min-width: 370px;
  background-image: linear-gradient(135deg,#00ccff,#9933ff 31%,#e646b6 52%,#fff9aa 77%,#00ff99,#00ccff);
  background-size: 200%;
}

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

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

form .search, form .btn {
  padding: 10px;
  border-radius: 2px;
  font-size: 16px;
  border: 1px solid white;
}

::placeholder {
  color: #f5f5f5;
}

form .search {
  width: 40%;
  min-width: 200px;
  max-width: 600px; 
}
form .search:focus {
  outline: 0;
  color: #333;
  background: white;
  box-shadow: 0 0 1px 1px rgba(0,0,0,0.3);
}

form .btn {
  cursor: pointer;
  width: 60px;
}
form .btn[type="submit"] {
  -webkit-appearance: button;
}
form .btn:hover {
  color: #333;
  background: white;
}
form .clear:hover {
  background: ;
}

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

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

.giphy img.gif {
  width: 50%;
  max-width: 600px;
  box-shadow: 0 0 2px 2px 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

              
                
// check other info returned by the API ???

var $form = $("form");
var $search = $(".search");
var $clear = $(".clear");
var $giphy = $(".giphy img");
var $giphyLink = $(".giphy a");

// launch function on form submit
$form.on("submit", function(e) {
  e.preventDefault();
  goGiphy();
});

// clear input on click
$clear.on("click", function() {
  $search.val("");
})

function goGiphy() {
  var input = $search.val();
  // Ajax call to giphy API  
  $.getJSON("https://api.giphy.com/v1/gifs/translate?api_key=bb2006d9d3454578be1a99cfad65913d&s=" + input, function(json) {
    data = JSON.parse(JSON.stringify(json));
    imgSrc = data.data.images.original.url;
    $giphy.fadeOut(1000);
    setTimeout( function() {
      $giphy.attr("src", imgSrc);
      $giphyLink.attr("href", imgSrc);
      setTimeout( function() {
        $giphy.addClass("gif");
        $giphy.fadeIn(1000);
      }, 800);
    }, 800);
  })
}

              
            
!
999px

Console