Add carousel
This commit is contained in:
41
static/carousel.js
Normal file
41
static/carousel.js
Normal file
@ -0,0 +1,41 @@
|
||||
function switchTab(e) {
|
||||
e.preventDefault();
|
||||
const tab = window.location.hash.substring(1);
|
||||
|
||||
// Unselect currently selected item.
|
||||
try {
|
||||
document
|
||||
.querySelector('.carousel-entry.on').classList.remove('on');
|
||||
document
|
||||
.querySelector('.carousel-item.on').classList.remove('on');
|
||||
} catch(e) {
|
||||
// pass
|
||||
}
|
||||
|
||||
// Select the new item.
|
||||
document
|
||||
.querySelector(`.carousel-entry.${tab}`)
|
||||
.classList.add('on');
|
||||
document
|
||||
.querySelector(`.carousel-item.${tab}`)
|
||||
.classList.add('on');
|
||||
}
|
||||
|
||||
function load() {
|
||||
// Add a listener for the location changing if window width supports it.
|
||||
if (window.innerWidth >= 960) {
|
||||
window.addEventListener('popstate', switchTab);
|
||||
} else {
|
||||
window.removeEventListener('popstate', switchTab);
|
||||
}
|
||||
}
|
||||
|
||||
// If we enter the page with no hash, select home.
|
||||
if (!window.location.hash) {
|
||||
history.pushState({}, '', '#home');
|
||||
}
|
||||
|
||||
// If we enter the page with a hash, select the current item.
|
||||
switchTab({preventDefault: () => {}});
|
||||
load();
|
||||
window.addEventListener('resize', load);
|
||||
@ -38,37 +38,17 @@ ul {
|
||||
}
|
||||
|
||||
.hero {
|
||||
max-width: 960px;
|
||||
margin: 0 auto;
|
||||
font-family: "Gentium Plus", serif;
|
||||
font-size: 18pt;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.hero blockquote {
|
||||
margin: 1rem 0;
|
||||
padding: 0 0 0 2rem;
|
||||
border-left: 3px solid #ddd;
|
||||
}
|
||||
|
||||
.hero p {
|
||||
text-indent: 2rem;
|
||||
}
|
||||
|
||||
.hero blockquote p {
|
||||
text-indent: 0;
|
||||
margin-bottom: 0.5rem;
|
||||
color: #444444;
|
||||
background-color: #fafafa;
|
||||
}
|
||||
|
||||
.hero ul {
|
||||
font-size: 20pt;
|
||||
color: #444444;
|
||||
background-color: #fafafa;
|
||||
list-style-type: none;
|
||||
text-align: center;
|
||||
flex: 2 1 100%;
|
||||
margin: 0;
|
||||
padding: 1rem;
|
||||
}
|
||||
@ -78,10 +58,59 @@ ul {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.hero .half {
|
||||
flex: 1 0 400px;
|
||||
margin: 0 1rem;
|
||||
max-width: 100%;
|
||||
.carousel nav {
|
||||
height: 5rem;
|
||||
width: 100%;
|
||||
display: block;
|
||||
margin: 0 auto;
|
||||
text-align: center;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.carousel nav ul {
|
||||
list-style-type: none;
|
||||
border-bottom: 1px solid #555;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.carousel nav li {
|
||||
display: inline-block;
|
||||
margin: 0;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
.carousel nav li.on {
|
||||
background-color: #555;
|
||||
}
|
||||
.carousel nav li.on a {
|
||||
color: #fff !important;
|
||||
}
|
||||
|
||||
.carousel nav li a {
|
||||
text-decoration: none;
|
||||
font-size: 16pt;
|
||||
}
|
||||
|
||||
.carousel .carousel-item {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.carousel .carousel-item.on {
|
||||
display: block;
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 960px) {
|
||||
.carousel nav {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.carousel .carousel-item {
|
||||
display: block;
|
||||
width: 100%;
|
||||
}
|
||||
.carousel .carousel-item h2 {
|
||||
display: block !important;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-device-width: 450px) {
|
||||
@ -94,22 +123,4 @@ ul {
|
||||
nav ul li {
|
||||
padding-bottom: 0.5rem !important;
|
||||
}
|
||||
.hero {
|
||||
display: block;
|
||||
margin: 0;
|
||||
padding: 0 2rem;
|
||||
width: 100%;
|
||||
}
|
||||
.hero ul {
|
||||
flex: none;
|
||||
width: 100%;
|
||||
padding: 0;
|
||||
background-color: initial;
|
||||
}
|
||||
.hero .half {
|
||||
flex: none;
|
||||
width: auto;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user