JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
<form class="search">
<input class="search-input" id="input" type="text" autocomplete="off"/>
<label class="search-label" for="input"></label>
<button class="search-button" type="reset"></button>
<div class="search-border"></div>
<div class="search-close">x</div>
</form>
* {
box-sizing: inherit;
margin: 0;
padding: 0;
}
html {
height: 100%;
box-sizing: border-box;
}
body {
width: 100%;
min-height: 100vh;
background-image: linear-gradient(to right, #4daf54, #3d8880);
display: flex;
align-items: center;
justify-content: center;
font-family: 'PT Sans', sans-serif;
}
.search {
width: 450px;
height: 120px;
position: relative;
overflow: hidden;
&-input {
width: 100%;
height: 100%;
padding: 0 65px 25px 60px;
position: absolute;
z-index: 1;
border: none;
outline: none;
background-color: rgba(255,255,255,.15);
color: #ddd;
font-size: 28px;
letter-spacing: .3px;
transform-origin: 10%;
transform: scaleX(0);
font-family: 'PT Sans', sans-serif;
}
&-button {
position: absolute;
right: 60px;
bottom: 33px;
width: 50px;
height: 50px;
border-radius: 50%;
border: 3px solid #fff;
background-color: transparent;
cursor: pointer;
outline: none;
transform: rotate(45deg);
-webkit-tap-highlight-color: transparent;
&::-moz-focus-inner {
border: 0;
}
}
&-label {
position: absolute;
top: 0;
left: 60px;
width: 325px;
height: 77px;
line-height: 95px;
color: #ddd;
font-size: 28px;
letter-spacing: .3px;
pointer-events: none;
overflow: hidden;
div {
white-space: pre;
}
}
&-border {
width: 25px;
height: 3px;
position: absolute;
right: 47px;
bottom: 32px;
transform: rotate(45deg);
background-color: #fff;
cursor: pointer;
}
&-text {
opacity: 0;
pointer-events: none;
}
&:before {
content: '';
position: absolute;
width: 3px;
height: 18px;
left: 40px;
top: 40px;
background-color: #fff;
opacity: 0;
transition: opacity .3s;
}
&.edge:before {
opacity: 1;
}
&-close {
position: absolute;
right: 15px;
top: 5px;
z-index: 5;
color: #fff;
font-size: 24px;
cursor: pointer;
opacity: 0;
pointer-events: none;
transition: opacity .4s;
&.visible {
opacity: 1;
pointer-events: auto;
transition-delay: .4s;
}
}
}
input::-ms-clear{
display: none;
}
let search = document.querySelector('.search');
let searchInp = search.children[0];
let searchLbl = search.children[1];
let searchBtn = search.children[2];
let searchBrd = search.children[3];
let searchCls = search.children[4];
let searchTxt, clonedTxt, clonedLbl, clonedLblWrap, animating = false, busy = true;
let TLTxt = new TimelineLite();
let TLSrch = new TimelineLite({onReverseComplete: () => {
TLTxt.clear();
animating = false;
}});
createTxt('Enter a search query', searchLbl, 'search-text');
searchTxt = document.querySelectorAll('.search-text');
searchBtn.addEventListener('click', () => {
if (!animating) animSearch();
});
searchBrd.addEventListener('click', () => {
if (!animating) animSearch();
});
searchInp.addEventListener('focus', () => {
if (busy || searchInp.value.trim().length) return;
TLTxt.isActive() ? TLTxt.play() : TLTxt.restart().timeScale(1).staggerTo(searchTxt, .07, {opacity: 0}, .035);
});
searchInp.addEventListener('blur', () => {
if (busy || searchInp.value.trim().length) return;
TLTxt.reverse().timeScale(1.3);
});
search.addEventListener('submit', e => {
e.preventDefault();
busy = true;
TLTxt.paused() ? TLTxt.clear() : TLTxt.play();
let val = searchInp.value.trim();
searchInp.disabled = true;
if (val.length) {
cloneLbl();
createLblTxt(val);
}
else TLSrch.reverse();
searchInp.value = '';
searchInp.blur();
});
searchCls.addEventListener('mousedown', e => {
e.preventDefault();
});
searchCls.addEventListener('click', () => {
if (busy) return;
busy = true;
let val = searchInp.value.trim();
searchInp.disabled = true;
if (val.length) {
cloneLbl();
createLblTxt(val);
}
else {
TLTxt.isActive() ? TLTxt.play() : TLTxt.progress() == 1 ? TLTxt.clear() :
TLTxt.restart().timeScale(1).staggerTo(searchTxt, .07, {opacity: 0}, .035);
TLSrch.reverse();
}
searchInp.value = '';
searchInp.blur();
});
function createTxt(text, elLbl, textClass) {
let splitText = [];
for (let i = text.length; i--;) {
splitText.unshift(`<span class='${textClass}'>${text[i]}</span>`);
}
elLbl.innerHTML = splitText.join('');
};
function createLblTxt(val) {
createTxt(val, clonedLbl, 'cloned-text');
clonedTxt = document.querySelectorAll('.cloned-text');
animClonedTxt(Array.from(clonedTxt).reverse());
}
function animSearch() {
animating = true;
TLSrch.restart()
.to(searchBrd, .4, {scaleX: 2, x: -25, y: -25, ease: Sine.easeIn})
.to(searchBtn, .4, {rotationX: 90, ease: Sine.easeIn}, '-=.4')
.to(searchBrd, .4, {rotation: 180, x: '-=6', y: '+=10', ease: Power2.easeInOut})
.set(searchBrd, {transformOrigin: '0', marginRight: '-38px'})
.to(searchBrd, .6, {scaleX: 13, ease: Power1.easeOut})
.set(search, {className: '+=edge', onComplete: showTxt})
.to(searchInp, .6, {scaleX: 1, ease: Sine.easeInOut}, '-=.3')
.set(searchCls, {className: '+=visible'})
.addPause();
}
function showTxt() {
let tl = new TimelineLite({onStart: () => {searchInp.disabled = true}});
tl.staggerTo(searchTxt, .07, {opacity: 1}, .035);
setTimeout(() => {
searchInp.disabled = false;
busy = false;
}, 300)
}
function animClonedTxt(el) {
let scrollW = clonedLbl.scrollWidth;
let offsetW = scrollW - clonedLbl.offsetWidth;
let tl = new TimelineLite({onComplete: () => {clonedLblWrap.remove()}});
tl.staggerTo(el, .08, {opacity: 0}, .04);
let tlDur = tl.totalDuration();
let offsetTime = (offsetW * tlDur) / scrollW;
if (offsetW > 0) {
TweenLite.fromTo(clonedLbl, offsetTime, {x: -offsetW}, {x: 0, delay: .2, ease: SlowMo.ease.config(0.1, 0.1, false)});
};
setTimeout(() => {
TLSrch.reverse();
}, Math.max((tlDur - .35) * 1000, 0));
}
function cloneLbl() {
clonedLblWrap = document.createElement('div');
clonedLblWrap.className = 'search-label';
search.appendChild(clonedLblWrap);
clonedLbl = document.createElement('div');
clonedLblWrap.appendChild(clonedLbl);
};
Also see: Tab Triggers