Skip to content

Commit

Permalink
use slick slider
Browse files Browse the repository at this point in the history
  • Loading branch information
nalam004 committed Apr 9, 2024
1 parent 839955e commit 7400bbd
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 70 deletions.
101 changes: 91 additions & 10 deletions css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,91 @@ svg {
overflow: hidden;
}

/* Slider */
.slick-slider {
position: relative;
display: block;
box-sizing: border-box;
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
touch-action: pan-y;
-webkit-tap-highlight-color: transparent;
}

.slick-list {
position: relative;
display: block;
margin: 0;
padding: 0;
}
.slick-list:focus {
outline: none;
}
.slick-list.dragging {
cursor: pointer;
cursor: hand;
}

.slick-slider .slick-track,
.slick-slider .slick-list {
transform: translate3d(0, 0, 0);
}

.slick-track {
position: relative;
left: 0;
top: 0;
display: block;
margin-left: auto;
margin-right: auto;
}
.slick-track:before, .slick-track:after {
content: "";
display: table;
}
.slick-track:after {
clear: both;
}
.slick-loading .slick-track {
visibility: hidden;
}

.slick-slide {
float: left;
height: 100%;
min-height: 1px;
display: none;
}
[dir=rtl] .slick-slide {
float: right;
}
.slick-slide img {
display: block;
}
.slick-slide.slick-loading img {
display: none;
}
.slick-slide.dragging img {
pointer-events: none;
}
.slick-initialized .slick-slide {
display: block;
}
.slick-loading .slick-slide {
visibility: hidden;
}
.slick-vertical .slick-slide {
display: block;
height: auto;
border: 1px solid transparent;
}

.slick-arrow.slick-hidden {
display: none;
}

/* VARIABLES */
/* MIXINS */
/* KEYFRAMES */
Expand Down Expand Up @@ -476,25 +561,21 @@ header .intro__guide .guide-button {
margin-left: auto;
margin-right: auto;
position: relative;
display: flex;
gap: 24px;
}
@media (max-width: 1200px) {
.guide-information .page-gallery {
margin-left: 32px;
margin-right: 32px;
}
}
.guide-information .page-gallery img {
box-shadow: 0px 8px 24px 0px rgba(30, 30, 30, 0.15);
border-radius: 8px;
width: 270px;
.guide-information .page-gallery .slick-slide {
cursor: grab;
max-width: 270px;
margin-right: 24px;
}
@media (max-width: 800px) {
.guide-information .page-gallery img {
width: 212px;
}
.guide-information .page-gallery .slick-slide img {
box-shadow: 0px 8px 24px 0px rgba(30, 30, 30, 0.15);
border-radius: 8px;
}

.testimonials {
Expand Down
2 changes: 1 addition & 1 deletion css/index.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions css/index.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import "./reset";
@import "../vendor/slick";

/* VARIABLES */
$creek: #26383B;
Expand Down Expand Up @@ -358,16 +359,18 @@ header {
.page-gallery {
@include inner();
position: relative;
display: flex;
gap: 24px;

img {
box-shadow: 0px 8px 24px 0px rgba(30, 30, 30, 0.15);
border-radius: 8px;
width: 270px;
.slick-slide {
cursor: grab;
max-width: 270px;
margin-right: 24px;

@media (max-width: 800px) { width: 212px; }
img {
box-shadow: 0px 8px 24px 0px rgba(30, 30, 30, 0.15);
border-radius: 8px;

//@media (max-width: 800px) { width: 212px; }
}
}
}
}
Expand Down
18 changes: 10 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ <h2>Just in time for the 2024 field season, this book will provide you with:</h2
</ul>
</div>

<figure class="page-gallery" data-mouse-down-at="0" data-prev-percentage="0">
<figure class="page-gallery">
<img src="./assets/page-1.jpeg" alt="Southern Gateways Guide Page" />
<img src="./assets/page-2.jpeg" alt="Southern Gateways Guide Page" draggable="false" />
<img src="./assets/page-3.jpeg" alt="Southern Gateways Guide Page" draggable="false" />
<img src="./assets/page-4.jpeg" alt="Southern Gateways Guide Page" draggable="false" />
<img src="./assets/page-5.jpeg" alt="Southern Gateways Guide Page" draggable="false" />
<img src="./assets/page-6.jpeg" alt="Southern Gateways Guide Page" draggable="false" />
<img src="./assets/page-7.jpeg" alt="Southern Gateways Guide Page" draggable="false" />
<img src="./assets/page-2.jpeg" alt="Southern Gateways Guide Page" />
<img src="./assets/page-3.jpeg" alt="Southern Gateways Guide Page" />
<img src="./assets/page-4.jpeg" alt="Southern Gateways Guide Page" />
<img src="./assets/page-5.jpeg" alt="Southern Gateways Guide Page" />
<img src="./assets/page-6.jpeg" alt="Southern Gateways Guide Page" />
<img src="./assets/page-7.jpeg" alt="Southern Gateways Guide Page" />
</figure>
</section>

Expand Down Expand Up @@ -162,6 +162,8 @@ <h2>Don’t get left behind in the Spring spawning run — order your copy toda
</div>
</footer>

<script src="index.js"></script>
<script type="text/javascript" src="vendor/jquery.min.js"></script>
<script type="text/javascript" src="vendor/slick.min.js"></script>
<script type="text/javascript" src="index.js"></script>
</body>
</html>
85 changes: 41 additions & 44 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,48 @@
// Function to fetch and insert SVG content
function fetchAndInsertSVG(containerId, svgPath) {
fetch(svgPath)
.then(response => response.text())
.then(svgData => {
document.getElementById(containerId).innerHTML = svgData;
})
.catch(error => console.error('Error loading SVG:', error));
fetch(svgPath)
.then(response => response.text())
.then(svgData => {
document.getElementById(containerId).innerHTML = svgData;
})
.catch(error => console.error('Error loading SVG:', error));
}

fetchAndInsertSVG('swim-svg-1', './assets/swim.svg');
fetchAndInsertSVG('swim-svg-2', './assets/swim.svg');

// Page gallery slider functionality
const track = document.querySelector('.page-gallery');
const images = track.querySelectorAll('img');
const imageWidth = images[0].offsetWidth;
const gap = 24;

let trackWidth = (imageWidth + gap) * images.length;
let maxDelta = trackWidth - track.offsetWidth;

window.onresize = () => {
imageWidth = images[0].offsetWidth;
trackWidth = (imageWidth + gap) * images.length;
maxDelta = trackWidth - track.offsetWidth;
};

window.onmousedown = (e) => {
track.dataset.mouseDownAt = e.clientX;
};

window.onmouseup = () => {
track.dataset.mouseDownAt = "0";
track.dataset.prevPercentage = track.dataset.percentage;
}

window.onmousemove = e => {
if(track.dataset.mouseDownAt === "0") return;

const mouseDelta = parseFloat(track.dataset.mouseDownAt) - e.clientX;

let nextPercentageUnconstrained = parseFloat(track.dataset.prevPercentage) - mouseDelta / maxDelta * 100;
nextPercentage = Math.max(Math.min(nextPercentageUnconstrained, 0), -(100 * (images.length - 1)));

track.dataset.percentage = nextPercentage;

if (!isNaN(nextPercentage)) {
track.style.transform = `translateX(${nextPercentage}%)`;
}
};
// Page gallery slick slider
$(document).ready(function() {
$('.page-gallery').slick({
slidesToShow: 4,
slidesToScroll: 3,
dots: false,
arrows: false,
infinite: false,
variableWidth: true,
responsive: [
{
breakpoint: 980,
settings: {
slidesToShow: 2,
slidesToScroll: 2,
}
},
{
breakpoint: 780,
settings: {
slidesToShow: 1,
slidesToScroll: 1,
}
},
{
breakpoint: 420,
settings: {
slidesToShow: 1,
slidesToScroll: 1,
variableWidth: false,
}
}
]
});
});
2 changes: 2 additions & 0 deletions vendor/jquery.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions vendor/slick.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 7400bbd

Please sign in to comment.