cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - 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.

            
              <div class="search">
  <input class="input" type="text">
  <svg viewBox="0 0 700 100" class="magnifying-glass">
    <path
          class="magnifying-glass-path"
          d="m 59.123035,59.123035 c -10.561361,10.56136 -27.684709,10.56136 -38.24607,0 -10.56136,-10.561361 -10.56136,-27.684709 0,-38.24607 10.561361,-10.56136 27.684709,-10.56136 38.24607,0 10.56136,10.561361 10.56136,27.684709 0,38.24607 l 28.876965,28.876965 c 6.304625,7.101523 5.754679,-0.187815 13.07143,-0.5 h 582.04101" />
    <path
          class="x"
          d="m 673.46803,25.714286 -37.17876,38.816532 c 0,0 -5.08857,5.60515 -5.68529,11.841734 -1.06622,11.143538 13.02902,11.127448 13.02902,11.127448" />
    <path
          class="x"
          d="m 635.08021,25.714286 37.17876,38.816532 c 0,0 5.08857,5.60515 5.68529,11.841734 1.06622,11.143538 -13.02902,11.127448 -13.02902,11.127448" />
  </svg>
  <div class="overlay overlay-1"></div>
  <div class="overlay overlay-2"></div>
</div>
            
          
!
            
              body {
  align-items: center;
  display: flex;
  height: 100vh;
  justify-content: center;
  margin: 0;
}
.search {
  position: relative;
  width: 300px;
}
.magnifying-glass {
  position: relative;
  transform: translateX(40%);
  transition: transform 500ms;
}
.search.active .magnifying-glass {
  transform: translateX(-7%);
}
.magnifying-glass-path {
  fill:none;
  stroke-dasharray: 210 808;
  stroke-linecap:round;
  stroke-width:6;
  stroke:#000;
  transition: stroke-dasharray 500ms, stroke-dashoffset 500ms;
}
.search.active .magnifying-glass-path {
  stroke-dasharray: 580 808;
  stroke-dashoffset: -224px;
}
.x {
  fill:none;
  stroke-dasharray: 56 92;
  stroke-dashoffset: -92px;
  stroke-linecap:round;
  stroke-width:6;
  stroke:#000;
  transition: stroke-dashoffset 500ms;
  visibility: hidden;
}
.search.active .x {
  visibility: visible;
}
.search.searching .x {
  stroke-dashoffset: 0;
}
.input {
  border: 0;
  font-size: 1.2em;
  left: 20px;
  outline: 0 !important;
  position: absolute;
  top: 4px;
}
.overlay {
  background: rgba(0,0,0,0);
  border-radius: 50%;
  cursor: pointer;
  position: absolute;
  transition: background 300ms;
}
.overlay-1 {
  height: 64px;
  left: 110px;
  top: -10px;
  width: 64px;
}
.overlay-2 {
  height: 38px;
  left: 240px;
  top: 0px;
  width: 38px;
}
.overlay:hover {
  background: rgba(0,0,0,0.08);
}
.search.active .overlay-1 {
  visibility: hidden;
}
.search:not(.active) .overlay-2,
.search:not(.searching) .overlay-2 {
  visibility: hidden;
}
            
          
!
            
              const overlay1 = document.querySelector('.overlay-1');
const overlay2 = document.querySelector('.overlay-2');
const search = document.querySelector('.search');
const input = document.querySelector('.input');
overlay1.addEventListener('click', () => {
  search.classList.toggle('active');
  if (search.classList.contains('active')) {
    setTimeout(() => {
      input.focus();
    }, 200)
  }
})
search.addEventListener('click', () => {
  if (search.classList.contains('active')) {
    setTimeout(() => {
      input.focus();
    }, 200)
  }
})
overlay2.addEventListener('click', (e) => {
  input.value = '';
  input.focus();
  search.classList.remove('searching')
})
document.body.addEventListener('click', (e) => {
  if (!search.contains(e.target) && input.value.length === 0) {
    search.classList.remove('active');
    search.classList.remove('searching');
    input.value = '';
  }
})
input.addEventListener('keyup', (e) => {
  if (e.keyCode === 13) {
    input.blur();
  }
})
input.addEventListener('input', () => {
  if (input.value.length > 0) {
    search.classList.add('searching')
  } else {
    search.classList.remove('searching')
  }
})
input.value = '';
input.blur();
            
          
!
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