Skip to content

Instantly share code, notes, and snippets.

@itchief
Created September 20, 2021 13:36
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 itchief/4236557238e5b5f67bc868afe10bd4ad to your computer and use it in GitHub Desktop.
Save itchief/4236557238e5b5f67bc868afe10bd4ad to your computer and use it in GitHub Desktop.
slider.php
<?php
$template = <<<HTML
<!doctype html>
<html lang="ru">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ChiefSlider</title>
<link rel="stylesheet" href="/examples/libs/chief-slider/chief-slider-with-prefixes.min.css">
<script defer src="/examples/libs/chief-slider/chief-slider.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
const slider = new ChiefSlider('.slider', {
loop: false
});
});
</script>
<style>
*,
*::before,
*::after {
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
'Helvetica Neue', Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
'Segoe UI Symbol';
}
.container {
max-width: 800px;
margin: 0 auto;
}
.slider__container {
padding-left: 0;
padding-right: 0;
}
.slider__items {
counter-reset: slide;
}
.slider__item {
-webkit-box-flex: 0;
-ms-flex: 0 0 100%;
flex: 0 0 100%;
max-width: 100%;
counter-increment: slide;
position: relative;
}
.slider__item::before {
content: counter(slide) "/4";
position: absolute;
top: 10px;
right: 20px;
color: #fff;
font-style: italic;
font-size: 32px;
font-weight: bold;
display: block;
}
img {
display: block;
width: 100%;
height: auto;
}
</style>
</head>
<body>
<div class="container">
<div class="slider">
<div class="slider__container">
<div class="slider__wrapper">
<div class="slider__items">{{items}}</div>
</div>
</div>
<a href="#" class="slider__control" data-slide="prev"></a>
<a href="#" class="slider__control" data-slide="next"></a>
</div>
</div>
</body>
</html>
HTML;
$items = [];
$path = '/examples/images/slider-images/';
$path = $_SERVER['DOCUMENT_ROOT'] . '/examples/images/slider-images/';
$images = glob($path . '*.jpg');
foreach($images as $image) {
$image = str_replace($_SERVER['DOCUMENT_ROOT'], '', $image);
$items[] = '<div class="slider__item"><img src="' . $image .'"></div>';
}
$html = str_replace('{{items}}', implode('', $items), $template);
echo $html;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment