<div class="box"></div>
<script>
if (CSS.paintWorklet) { CSS.paintWorklet.addModule('/t_afif/pen/f948d37e306e7824171c0007674272e0.js');
}
</script>
@property --f-o{
syntax: '<number>';
inherits: false;
initial-value: 1;
}
.box {
--r:2/1; /* ratio */
--d:10s; /* duration */
--f-n:40;
--f-m:20;
-webkit-mask: paint(fragmentation);
mask: paint(fragmentation);
max-width:800px;
aspect-ratio: var(--r);
background:
url(https://picsum.photos/id/15/800/400),
url(https://picsum.photos/id/110/800/400),
url(https://picsum.photos/id/1014/800/400),
url(https://picsum.photos/id/305/800/400);
background-repeat:no-repeat;
margin:auto;
animation:
c var(--d) linear infinite ,
i calc(var(--d)/8) linear infinite alternate calc(var(--d)/8);
}
@keyframes c {
0% ,24.9% {background-size:cover,0 0,0 0,0 0}
25%,49.9% {background-size:0 0,cover,0 0,0 0}
50%,74.9% {background-size:0 0,0 0,cover,0 0}
75%,100% {background-size:0 0,0 0,0 0,cover}
}
@keyframes i {
0%,15% {--f-o:1}
100% {--f-o:0}
}
body {
background:pink;
}
registerPaint('fragmentation', class {
static get inputProperties() {
return [
'--f-n',
'--f-m',
'--f-o'
]
}
paint(ctx, size, properties) {
const n = properties.get('--f-n');
const m = properties.get('--f-m');
const o = properties.get('--f-o');
const w = size.width/n;
const h = size.height/m;
const l = 10;
const mask = 0xffffffff;
const seed = 30;
let m_w = (123456789 + seed) & mask;
let m_z = (987654321 - seed) & mask;
let random = function() {
m_z = (36969 * (m_z & 65535) + (m_z >>> 16)) & mask;
m_w = (18000 * (m_w & 65535) + (m_w >>> 16)) & mask;
var result = ((m_z << 16) + (m_w & 65535)) >>> 0;
result /= 4294967296;
return result;
}
for(var i=0;i<n;i++) {
for(var j=0;j<m;j++) {
ctx.fillStyle = 'rgba(0,0,0,'+((random()*(l-1) + 1) - (1-o)*l)+')';
ctx.fillRect(i*w-.5, j*h-.5, w+.5, h+.5);
}
}
}
})
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.