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.
<ul id="flag" class="flag"></ul>
* {
margin: 0;
padding: 0;
}
html,
body {
height: 100%;
width: 100%;
}
li {
list-style: none;
}
.flag {
position: absolute;
left: 50%;
top: 50%;
animation: wave ease-in-out infinite;
}
.flag > li {
height: 100%;
float: left;
background-image: url("https://fish-pond-1253945200.cos.ap-guangzhou.myqcloud.com/others/chinese/flag.jpg");
background-size: auto 100%;
animation: flag ease-in-out infinite;
}
const flag = document.querySelector('#flag')
const image = new Image()
image.src = 'https://fish-pond-1253945200.cos.ap-guangzhou.myqcloud.com/others/chinese/flag.jpg'
const flagWidth = 800
const flagHeight = 640
let imgWidth = ''
let imgHeight = ''
const imgRender = ({
sliceCount = 70,
amplitude = 20,
period = 1.5,
duration = 2,
}) => {
const style = document.createElement('style')
const styleSplinter = []
const sliceCountPerPeriod = Math.floor(sliceCount / period)
const sliceWidth = imgWidth / sliceCount
const formula = sliceCountPerPeriod + 'n+'
const delay = (duration * period / sliceCount)
for (let i = 0; i < sliceCount; ++i) {
if (i < sliceCountPerPeriod) {
styleSplinter.push(`
.flag > li:nth-child(${formula + i}) {
animation-delay: -${delay * (sliceCountPerPeriod - i)}s;
}
`)
}
styleSplinter.push(`
.flag > li:nth-child(${i}) {
background-position: -${i * sliceWidth}px 0;
}
`)
}
styleSplinter.push(`
@keyframes flag {
0% { transform: translate3d(0, ${amplitude}px, 0); }
50% { transform: translate3d(0, ${-amplitude}px, 0); }
100% { transform: translate3d(0, ${amplitude}px, 0); }
}
@keyframes wave {
0% { transform: translate3d(0, ${-amplitude}px, 0); }
50% { transform: translate3d(0, ${amplitude}px, 0); }
100% { transform: translate3d(0, ${-amplitude}px, 0); }
}
.flag {
animation-duration: ${duration}s;
animation-delay: -${delay * sliceCountPerPeriod}s;
}
.flag > li {
animation-duration: ${duration}s;
width: ${imgWidth / sliceCount}px;
}
`)
style.innerHTML = styleSplinter.join('')
flag.innerHTML = new Array(sliceCount + 1).join('<li></li>')
document.documentElement.appendChild(style)
}
image.onload = () => {
imgWidth = image.width
imgHeight = image.height
const ratio = image.width / image.height
if (imgWidth > flagWidth) {
imgWidth = flagWidth
imgHeight = imgWidth / ratio
}
if (imgHeight > flagHeight) {
imgWidth = imgHeight * ratio
imgHeight = flagHeight
}
flag.style.width = imgWidth + 'px'
flag.style.height = imgHeight + 'px'
flag.style.marginLeft = -imgWidth / 2 + 'px'
flag.style.marginTop = -imgHeight / 2 + 'px'
imgRender({
sliceCount: 70,
amplitude: 20,
period: 1.5,
duration: 2,
})
}
Also see: Tab Triggers