Skip to content

Instantly share code, notes, and snippets.

@bwente
Created March 27, 2023 00:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bwente/8439203d6b3b0b8b476b122330f31703 to your computer and use it in GitHub Desktop.
Save bwente/8439203d6b3b0b8b476b122330f31703 to your computer and use it in GitHub Desktop.
Lottie Animation Player for MODX
<?php
$modx->regClientStartupScript('https://unpkg.com/@lottiefiles/lottie-player@latest/dist/lottie-player.js');
$background = $modx->getOption('background', $scriptProperties, 'transparent');
$speed = $modx->getOption('speed', $scriptProperties, 1);
$width = $modx->getOption('width', $scriptProperties, '100%');
$height = $modx->getOption('height', $scriptProperties, '100%');
$hover = $modx->getOption('hover', $scriptProperties, 0);
$loop = $modx->getOption('loop', $scriptProperties, 0);
$controls = $modx->getOption('controls', $scriptProperties, 0);
$autoplay = $modx->getOption('autoplay', $scriptProperties, 1);
$json = $modx->getOption('lottieJSON', $scriptProperties, '');
$id = $modx->getOption('id', $scriptProperties, 'animation');
if ($hover == 1) {
$hover = 'hover';
}
if ($loop == 1) {
$loop = 'loop';
}
if ($controls == 1) {
$controls = 'controls';
}
if ($autoplay == 1) {
$autoplay = 'autoplay';
}
$player = '<lottie-player id="' . $id . '" src="' . $json . '"';
$player .= ' background="' . $background . '"';
$player .= ' speed="' . $speed . '"';
$player .= ' style="width: ' . $width . '; height: ' . $height . '"';
if ($hover) {
$player .= ' ' . $hover;
}
if ($loop) {
$player .= ' ' . $loop;
}
if ($controls) {
$player .= ' ' . $controls;
}
if ($autoplay) {
$player .= ' ' . $autoplay;
}
$player .= '></lottie-player>';
echo $player;
return;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment