Skip to content

Instantly share code, notes, and snippets.

@xiCO2k
Created October 13, 2022 17:11
Show Gist options
  • Save xiCO2k/9d51d2c34093bb863fbd7c448ca19ecf to your computer and use it in GitHub Desktop.
Save xiCO2k/9d51d2c34093bb863fbd7c448ca19ecf to your computer and use it in GitHub Desktop.
Infinite Image fadeIn fadeOut
<div
class="relative pointer-events-none"
x-data="{ active: 0 }"
x-init="setInterval(() =>
active = ++active > $el.childElementCount - 1 ? 0 : active
, 3000)"
>
@foreach([
'hero-pic1.webp',
'hero-pic2.webp',
'hero-pic3.webp',
'hero-pic4.webp',
] as $index => $image)
<div
class="absolute h-full w-full bg-cover"
style="background-image: url({{ Vite::asset("resources/img/{$image}") }})"
x-show="active === {{ $index }}"
x-transition.opacity.duration.500ms
></div>
@endforeach
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment