use Elementor\Widget_Base;
use Elementor\Controls_Manager;
+use function Roots\asset;
+
class HeaderSlideshow extends Widget_Base {
* @return array Widget scripts dependencies.
*/
public function get_script_depends() {
- return [];
+
+ wp_register_script(
+ 'cube-header-slideshow',
+ asset('scripts/header-slideshow.js'),
+ [], // Dependencies
+ null, // Version
+ true // In footer?
+ );
+
+ return ['cube-header-slideshow'];
}
/**
* Register the widget controls.
<div class="header-slideshow elementor" id="<?= $id ?>">
+ <?php foreach($images as $image): ?>
+ <div class="header-slideshow-image" style="background-image:url(<?= wp_get_attachment_image_url($image['id'], 'full') ?>);"></div>
+ <?php endforeach; ?>
+
<?php
/*
Here we're hijacking Elementor's built in entrance animations for the title text.
*/
?>
- <?php // Todo: add simple image slideshow with crossfade + nav (no need for a library) ?>
-
- <div class="header-slideshow-sizer" style="padding-bottom: <?= $image_ratio ?>; background-image:url(/wp-content/uploads/<?= $image_meta['file'] ?>);">
+ <div class="header-slideshow-sizer" style="padding-bottom: <?= $image_ratio ?>;">
<div class="header-slideshow-content mx-2v elementor-element elementor-invisible" data-settings='{"animation":"fadeInRight","animation_delay":0}' data-element_type="section">
<h1 class="header-slideshow-title">
--- /dev/null
+<svg xmlns="http://www.w3.org/2000/svg" width="26" height="44" viewBox="0 0 26 44"><path stroke-width="5" fill="none" d="M2 42l20-20L2 2"/></svg>
--- /dev/null
+<svg xmlns="http://www.w3.org/2000/svg" width="26" height="44" viewBox="0 0 26 44"><path stroke-width="5" fill="none" d="M24 2L4 22l20 20"/></svg>
--- /dev/null
+// ELEMENTOR Trigger
+(function($) {
+ $(window).on('elementor/frontend/init', function () {
+ elementorFrontend.hooks.addAction('frontend/element_ready/cube-header-slideshow.default', function ($scope) {
+
+ // Inspired by: https://www.sitepoint.com/make-a-simple-javascript-slideshow-without-jquery/
+ const slides = $scope.find('.header-slideshow-image');
+ const slideInterval = setInterval(nextSlide, 3000);
+ let currentSlide = 0;
+
+ function showSlide(index) {
+ $(slides[currentSlide]).removeClass('showing');
+ currentSlide = (index + slides.length) % slides.length;
+ $(slides[currentSlide]).addClass('showing');
+ }
+
+ function nextSlide() {
+ showSlide(currentSlide + 1);
+ }
+ function prevSlide() {
+ showSlide(currentSlide - 1);
+ }
+
+ });
+ });
+})(jQuery);
width: 100%
height: 100%
background-image: linear-gradient(to bottom, #fff 10%, transparent 50%)
+ z-index: 5
+
+ &-image
+ background-repeat: no-repeat
+ background-size: cover
+ position: absolute
+ top: 0
+ left: 0
+ width: 100%
+ height: 100%
+ z-index: 1
+ opacity: 0
+ transition: opacity 0.75s
+
+ &.showing
+ opacity: 1
+ z-index: 2
&-content
+ z-index: 10
position: absolute
constrain(left, 5vw)
constrain(bottom, 10vw)
.link-carousel
&-item
+ height: auto !important // Needed to make equal heights, otherwise Swiper's 100% height breaks this
display: flex
align-items: center
flex-direction: column
cursor: pointer
- border-right: 1px solid rgba(#fff, 0.2)
- height: auto !important // Needed to make equal heights, otherwise Swiper's 100% height breaks this
+ +above(500px)
+ border-right: 1px solid rgba(#fff, 0.2)
&-image
flex-grow: 1
.link-carousel-item:hover &
@apply bg-teal
+
+
+ &-prev, &-next
+ position: absolute
+ top: 50%
+ transform: translateY(-50%)
+ z-index: 10
+ stroke: currentColor
+ transition: color 0.25s
+
+ &:hover
+ @apply text-pink
+
+ &-prev
+ left: 0.5rem
+ &-next
+ right: 0.5rem
<header class="site bg-white font-display font-medium uppercase text-sm">
<div class="container relative pl-2v pr-1v pt-8 pb-12 flex items-center justify-between">
- <a class="flex-shrink-0 mr-4" href="{{ home_url('/') }}" aria-label="<?= _("Go to the home page") ?>">
+ <a class="flex-shrink-0 mr-4"
+ style="max-width: 45%; min-width: 180px"
+ href="{{ home_url('/') }}"
+ aria-label="<?= _("Go to the home page") ?>">
<img class="header-logo" src="@asset('images/logo.svg')" alt="{{ get_bloginfo('name', 'display') }}">
</a>
768 => [
'slidesPerView' => 2
],
+ 499 => [
+ 'slidesPerView' => 1
+ ],
],
'navigation' => [
- 'nextEl' => '.swiper-button-next',
- 'prevEl' => '.swiper-button-prev',
+ 'nextEl' => '.link-carousel-next',
+ 'prevEl' => '.link-carousel-prev',
],
];
</a>
@endforeach
</div>
- <div class="swiper-button-prev"></div>
- <div class="swiper-button-next"></div>
+ <div class="link-carousel-prev">@svg('carousel-prev', 'stroke-current')</div>
+ <div class="link-carousel-next">@svg('carousel-next', 'stroke-current')</div>
</div>
// JavaScript
mix.js(src`scripts/app.js`, 'scripts')
+ .js(src`scripts/header-slideshow.js`, 'scripts')
.js(src`scripts/link-carousel.js`, 'scripts')
.js(src`scripts/customizer.js`, 'scripts')
.extract();