Files
Festive-Seasons-Pro/assets/js/easter-eggs.js

42 lines
1.4 KiB
JavaScript

(function($) {
// Skript nur ausführen, wenn die body-Klasse 'festive-easter' vorhanden ist
if (!$('body').hasClass('festive-easter')) {
return;
}
// Pfad zum Plugin-Verzeichnis wird von PHP übergeben (siehe wp_localize_script)
const pluginUrl = fsp_vars.plugin_url;
const eggImages = [
pluginUrl + 'assets/img/easter-egg-1.png',
pluginUrl + 'assets/img/easter-egg-2.png',
pluginUrl + 'assets/img/easter-egg-3.png',
pluginUrl + 'assets/img/easter-egg-4.png',
pluginUrl + 'assets/img/easter-egg-5.png',
pluginUrl + 'assets/img/easter-egg-6.png',
pluginUrl + 'assets/img/easter-egg-7.png',
pluginUrl + 'assets/img/easter-egg-8.png',
pluginUrl + 'assets/img/easter-egg-9.png'
];
function createEgg() {
const randomEgg = eggImages[Math.floor(Math.random() * eggImages.length)];
const $egg = $('<img>').attr('src', randomEgg).css({
position: 'fixed',
width: '60px',
left: Math.random() * 100 + '%',
top: '-80px',
zIndex: 9999,
pointerEvents: 'none',
transform: 'translateX(-50%)'
});
$('body').append($egg);
$egg.animate({ top: '110vh' }, 7000, 'linear', function() {
$(this).remove();
});
}
setInterval(createEgg, 900);
})(jQuery);