Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add a Ken Burns effect to MetaSlider using FlexSlider
<?php
$slideshow_id = '236';
add_filter('metaslider_css_classes', function($classes, $id) use ($slideshow_id) {
if ($id != $slideshow_id) return $classes;
return $classes . ' kenburns-effect';
}, 10, 2);
add_filter('metaslider_css', function($css, $settings, $id) use ($slideshow_id) {
if ($id != $slideshow_id) return $css;
return $css . "
.kenburns-effect .flexslider .slides,
.kenburns-effect .flexslider .slides > li {
overflow: hidden;
}
.kenburns-effect .flexslider .slides > li .kenburns-inner {
background-size: cover;
background-position: center;
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
}
.kenburns-effect .flexslider .slides img {
opacity: 0;
}
.kenburns-effect .flexslider .slides > li.flex-active-slide .kenburns-inner {
animation: kb-zoom-out {$settings['delay']}ms;
}
@-webkit-keyframes kb-zoom-out {
0% {
transform: scale(1.3);
}
100% {
transform: scale(1);
}
}";
}, 10, 3);
add_filter('metaslider_flex_slider_list_item_attributes', function($attributes, $slide, $id) use ($slideshow_id) {
if ($id != $slideshow_id) return $attributes;
$movements = ['center left', 'center center', 'center right', 'top left', 'top center', 'top right', 'bottom left', 'bottom center', 'bottom right'];
$attributes['data-background'] = isset($slide['src']) ? $slide['src'] : '';
$attributes['data-movement'] = $movements[array_rand($movements)];
return $attributes;
}, 10, 3);
add_filter('metaslider_flex_slider_javascript', function($js, $id) use ($slideshow_id) {
if ($id != $slideshow_id) return $js;
return $js . ";window.jQuery('.kenburns-effect .slides .ms-image').each(function() {
var background = $(this).data('background');
var movement = $(this).data('movement');
$(this).prepend(\"<div class='kenburns-inner' style='background-image:url(\" + background + \");transform-origin:\" + movement + \"'></div>\");
});";
}, 10, 2);
@KevinBatdorf
Copy link
Author

KevinBatdorf commented Feb 12, 2020

@KevinBatdorf
Copy link
Author

KevinBatdorf commented Feb 12, 2020

@KevinBatdorf
Copy link
Author

KevinBatdorf commented Feb 12, 2020

In case the URL goes down, see it here: https://www.youtube.com/watch?v=Rz-AB0ssFbo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment