console
(function(){
const getSafeDistance = () => {
const viewportDiagonal = Math.sqrt(
window.innerWidth ** 2 + window.innerHeight ** 2
);
return Math.floor((viewportDiagonal - window.innerWidth) / 2);
}
const maxSafeDistance = getSafeDistance();
const animationPresets = {
scalePulse: () => {
const scale = (0.8 + Math.random() * 0.4).toFixed(2);
return {
keyframes: [
{ transform: `scale(1)` },
{ transform: `scale(${scale})` },
{ transform: `scale(1)` }
]
};
},
horizontalMove: () => {
const distance = Math.floor(Math.random() * maxSafeDistance * 0.3);
const direction = Math.random() > 0.5 ? 1 : -1;
return {
keyframes: [
{ transform: `translateX(${direction * distance}%)` },
{ transform: `translateX(${-direction * distance}%)` }
]
};
},
verticalMove: () => {
const distance = Math.floor(Math.random() * maxSafeDistance * 0.3);
return {
keyframes: [
{ transform: `translateY(${distance}%)` },
{ transform: `translateY(-${distance}%)` }
]
};
},
rotateSwing: () => {
const angle = Math.floor(Math.random() * 15 + 5);
return {
keyframes: [
{ transform: `rotate(-${angle}deg)` },
{ transform: `rotate(${angle}deg)` }
]
};
},
diagonalMove: () => {
const distance = Math.floor(Math.random() * maxSafeDistance * 0.3);
return {
keyframes: [
{ transform: `translate(${distance}%, ${distance}%)` },
{ transform: `translate(-${distance}%, -${distance}%)` }
]
};
}
};
class AnimationManager {
constructor() {
this.styleTag = document.createElement('style');
document.head.appendChild(this.styleTag);
this.currentAnimation = null;
}
generateAnimationParams() {
const types = Object.keys(animationPresets);
const type = types[Math.floor(Math.random() * types.length)];
return {
type,
duration: Math.floor(Math.random() * 10 + 5),
timing: ['ease', 'ease-in', 'ease-out', 'ease-in-out', 'linear'][Math.floor(Math.random() * 5)]
};
}
createAnimation() {
const params = this.generateAnimationParams();
const { keyframes } = animationPresets[params.type]();
const animationName = `anim-${Date.now()}`;
let css = `@keyframes ${animationName} {`;
keyframes.forEach((frame, index) => {
css += `${(index * 100) / (keyframes.length - 1)}% {
transform: ${frame.transform};
}`;
});
css += '}';
let bgUrl = document.querySelector('.mmPlayer-bg').style['background-image']
if (bgUrl) {
css += `.mmPlayer-bg::before {
animation: ${animationName} ${params.duration}s ${params.timing} infinite;
background-image: `+bgUrl+`;
}`;
} else {
css += `.mmPlayer-bg::before {
animation: ${animationName} ${params.duration}s ${params.timing} infinite;
}`;
}
this.styleTag.textContent = css;
this.currentAnimation = animationName;
}
startRandomCycle() {
this.createAnimation();
setTimeout(() => this.startRandomCycle(), (Math.random() * 5 + 5) * 1000);
}
}
const animator = new AnimationManager();
animator.startRandomCycle();
window.addEventListener('resize', () => {
document.querySelector('.mmPlayer-bg').style.backgroundSize = 'cover';
});
})()
<body>
<div class="mmPlayer-bg"></div>
</body>
.mmPlayer-bg {
position: fixed;
top: 50%;
left: 50%;
width: 150vw;
height: 150vh;
transform: translate(-50%, -50%);
overflow: hidden;
z-index: -1;
will-change: transform;
backface-visibility: hidden;
}
.mmPlayer-bg::before {
content: '';
position: absolute;
top: -25%;
left: -25%;
width: 150%;
height: 150%;
background-image: url('https://p2.music.126.net/iBZWVshMiRIGH1BMFhebSA==/109951168606827722.jpg?paramx=300y300');
background-position: center;
background-size: cover;
background-blend-mode: multiply;
filter: blur(50px);
}