up
This commit is contained in:
parent
4ae129054e
commit
ab9ab64bd5
476 changed files with 3370 additions and 532 deletions
|
@ -0,0 +1,65 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="carousel" class="carousel">
|
||||
<button class="arrow prev">⇦</button>
|
||||
<div class="gallery">
|
||||
<ul class="images">
|
||||
<li><img src="https://en.js.cx/carousel/1.png"></li>
|
||||
<li><img src="https://en.js.cx/carousel/2.png"></li>
|
||||
<li><img src="https://en.js.cx/carousel/3.png"></li>
|
||||
<li><img src="https://en.js.cx/carousel/4.png"></li>
|
||||
<li><img src="https://en.js.cx/carousel/5.png"></li>
|
||||
<li><img src="https://en.js.cx/carousel/6.png"></li>
|
||||
<li><img src="https://en.js.cx/carousel/7.png"></li>
|
||||
<li><img src="https://en.js.cx/carousel/8.png"></li>
|
||||
<li><img src="https://en.js.cx/carousel/9.png"></li>
|
||||
<li><img src="https://en.js.cx/carousel/10.png"></li>
|
||||
</ul>
|
||||
</div>
|
||||
<button class="arrow next">⇨</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
/* label the images, just for convenience, to visually track them */
|
||||
let i = 1;
|
||||
for(let li of carousel.querySelectorAll('li')) {
|
||||
li.style.position = 'relative';
|
||||
li.insertAdjacentHTML('beforeend', `<span style="position:absolute;left:0;top:0">${i}</span>`);
|
||||
i++;
|
||||
}
|
||||
|
||||
/* configuration */
|
||||
let width = 130; // image width
|
||||
let count = 3; // visible images count
|
||||
|
||||
let list = carousel.querySelector('ul');
|
||||
let listElems = carousel.querySelectorAll('li');
|
||||
|
||||
let position = 0; // ribbon scroll position
|
||||
|
||||
carousel.querySelector('.prev').onclick = function() {
|
||||
// shift left
|
||||
position += width * count;
|
||||
// can't move to the left too much, end of images
|
||||
position = Math.min(position, 0)
|
||||
list.style.marginLeft = position + 'px';
|
||||
};
|
||||
|
||||
carousel.querySelector('.next').onclick = function() {
|
||||
// shift right
|
||||
position -= width * count;
|
||||
// can only shift the ribbbon for (total ribbon length - visible count) images
|
||||
position = Math.max(position, -width * (listElems.length - count));
|
||||
list.style.marginLeft = position + 'px';
|
||||
};
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,70 @@
|
|||
body {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.carousel {
|
||||
position: relative;
|
||||
width: 398px;
|
||||
padding: 10px 40px;
|
||||
border: 1px solid #CCC;
|
||||
border-radius: 15px;
|
||||
background: #eee;
|
||||
}
|
||||
|
||||
.carousel img {
|
||||
width: 130px;
|
||||
height: 130px;
|
||||
/* make it block to remove space around images */
|
||||
display: block;
|
||||
}
|
||||
|
||||
.arrow {
|
||||
position: absolute;
|
||||
top: 60px;
|
||||
padding: 0;
|
||||
background: #ddd;
|
||||
border-radius: 15px;
|
||||
border: 1px solid gray;
|
||||
font-size: 24px;
|
||||
line-height: 24px;
|
||||
color: #444;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.arrow:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.arrow:hover {
|
||||
background: #ccc;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.prev {
|
||||
left: 7px;
|
||||
}
|
||||
|
||||
.next {
|
||||
right: 7px;
|
||||
}
|
||||
|
||||
.gallery {
|
||||
width: 390px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.gallery ul {
|
||||
height: 130px;
|
||||
width: 9999px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
transition: margin-left 250ms;
|
||||
/* remove white-space between inline-block'ed li */
|
||||
/* http://davidwalsh.name/remove-whitespace-inline-block */
|
||||
font-size: 0;
|
||||
}
|
||||
|
||||
.gallery li {
|
||||
display: inline-block;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue