const array = [ 'fatfish', 'hello', 'world', 24 ]
console.log(array.indexOf('fatfish')) // 0
console.log(array.indexOf('medium')) // -1
const array = [
{
name: 'fatfish'
},
{
name: 'hello'
},
{
name: 'world'
},
]
const index = array.findIndex((it) => it.name === 'fatfish') // 0
const array = [ 1, [ 2, [ 3, [ 4, [ 5 ] ] ] ] ]
const flattenArray = (array) => {
return array.reduce((res, it) => {
return res.concat(Array.isArray(it) ? flattenArray(it) : it)
}, [])
}
console.log(flattenArray(array)) // [1, 2, 3, 4, 5]
const prizes = [ 'A', 'B', 'C', 'D' ]
prizes.sort(() => 0.5 - Math.random())
/* https://codepen.io/collection/XPjvPP/ */
/* Render items as columns */
.container {
display: flex;
flex-flow: column wrap;
}
/* Re-order items into rows */
.item:nth-child(3n+1) { order: 1; }
.item:nth-child(3n+2) { order: 2; }
.item:nth-child(3n) { order: 3; }
/* Force new columns */
.container::before,
.container::after {
content: "";
flex-basis: 100%;
width: 0;
order: 2;
}
/* https://jsbin.com/piwefoxacu/edit?html,css,output */
a {
position: relative;
color: #000;
text-decoration: none;
}
a:hover {
color: #000;
}
a::before {
content: "";
position: absolute;
display: block;
width: 100%;
height: 2px;
bottom: 0;
left: 0;
background-color: #000;
transform: scaleX(0);
transition: transform 0.3s ease;
}
a:hover::before {
transform: scaleX(1);
}
/* Animate the line from the right */
a::before {
content: "";
position: absolute;
display: block;
width: 100%;
height: 2px;
bottom: 0;
left: 0;
background-color: #000;
transform: scaleX(0);
transform-origin: top right;
transition: transform 0.3s ease;
}
const lis = [...document.querySelectorAll("#wizard > li")];
lis.forEach((li) => {
li.addEventListener("click", () => {
const index = lis.indexOf(li);
console.log(index);
});
});
// https://thewebdev.info/2022/04/22/how-to-get-the-bodys-content-of-an-iframe-in-javascript/
const iframe = document.querySelector("#id_description_iframe");
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
const iframeContent = iframeDocument.querySelectorAll("#frameBody");
/* https://css-tricks.com/full-width-containers-limited-width-parents/ */
/* With Known % Width */
main {
width: 60%;
margin: 0 auto;
/* creates 20% margins on either side */
}
.full-width {
/* 1/3 of 60% = the 20% margin on either side */
margin-left: -33.33%;
margin-right: -33.33%;
}
/* With Known Non-% Parent Width */
@media (min-width: 500px) {
main {
width: 500px;
margin: 0 auto;
}
.full-width {
margin-left: calc(-100vw / 2 + 500px / 2);
margin-right: calc(-100vw / 2 + 500px / 2);
}
}
@media (min-width: $max-width) {
.full-width {
margin-left: calc(50% - 50vw);
margin-right: calc(50% - 50vw);
}
}
@supports (width: 100vw) {
.full-width {
width: 100vw;
}
@media all and (min-width: 40rem) {
.full-width {
transform: translateX(calc((40rem - 100vw)/2));
}
}
}
/* No calc() needed */
.full-width {
width: 100vw;
position: relative;
left: 50%;
right: 50%;
margin-left: -50vw;
margin-right: -50vw;
}
/*
tohle asi taky funguje
.my-image{
max-width: 100vw;
width: 100vw;
margin: 0 calc(-50vw + 50%);
height: 70vh;
}
*/
<!-- https://codepen.io/codegem-io/pen/poeeZOd -->
<style>
.wrapper {
display: block;
position: relative;
width: 300px;
}
.placeholder {
position: absolute;
left: 9px;
top: 13px;
padding: 0 4px;
color: var(--accent-color);
background-color: var(--bkg-color);
transform-origin: top left;
transition: all 120ms ease-in;
}
.textfield:focus + .placeholder,
.textfield:not(:placeholder-shown) + .placeholder {
top: -5px;
transform: scale(0.8);
font-weight: bold;
}
</style>
<label class="wrapper">
<input type="input" class="textfield" autocomplete="off" placeholder=" " />
<span class="placeholder">Name</span>
</label>