HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div class="brand" style="background:black; text-align:center;"><a href="https://www.creativecodingclub.com/bundles/creative-coding-club?src=cdp3droll" target="_blank"><img src="https://assets.codepen.io/32887/logo-ill.svg" width="300" alt="" /></a></div>
<div class="space" style="padding:20px; background:#efefef;">
<h3>Use mouse wheel to scroll down and navigate Swiper gallery.</h3>
<ul style="font-family:sans-serif;">
<li>This is a rough proof of concept</li>
<li>Not set up to be fully responsive</li>
<li>There are intermittent glitches</li>
<li>Use at own risk</li>
<li><strong style="color:#600;">Zero support is offered for any fixes or updates</strong></li>
<li>The community is welcome to hack on this and try to improve it</li>
</ul>
<h3>Swipe to unlock pining</h3>
<p>When the gallery gets pinned be sure to Swipe until the last slide is visible</p>
<p>Now you can scroll down to the rest of the page. Neat!</p>
<h3>Known Issues</h3>
<ul style="font-family:sans-serif;">
<li>If you get to slide 6 and scroll all the way down, sometimes on the way up you can bypass the pinning and navigation through the Swiper gallery.</li>
<li>Sometimes when going back up the page the pinned Swiper section glitches out. Elements flash and jump a bit. I have no idea what's going on here but I suspect the scroll position is jumping up and down.</li>
<li>Attempting to use the Scrollbar while scrolling is disabled results in lots jitters and flasing.</li>
<li>After page loads fresh, grab scrollbar and try to scroll down the full page. It becomes a mess when you hit the section that is trying to disable scrolling.</li>
</ul>
</div>
<div class="gallery">
<div class="swiper">
<div class="swiper-wrapper">
<div class="swiper-slide red">
<h1>A</h1>
<h2>Is for Apple</h2>
</div>
<div class="swiper-slide gray">
<h1>B</h1>
<h2>Is for Banana</h2>
</div>
<div class="swiper-slide blue">
<h1>C</h1>
<h2>Is for Car</h2>
</div>
<div class="swiper-slide purple">
<h1>D</h1>
<h2>Is for Desk</h2>
</div>
<div class="swiper-slide orange">
<h1>E</h1>
<h2>Is for Eggs</h2>
</div>
<div class="swiper-slide green">
<h1>F</h1>
<h2>Is for Fabulous</h2>
</div>
</div>
</div>
<div id="currentSlide" style="font-size:4vh; font-weight:bold; font-family:sans-serif; width:8em; padding:20px; background:#ccc; border-radius:2.5em; text-align:center; margin:20px auto auto auto">1</div>
</div>
<div class="space" style="padding:20px; background:#efefef;">
<h3>Closing Thoughts</h3>
<p>Even though this seems like a neat UI treatment, it is very strange to lock the scrollbar in place. I really don't think the user should be prevented from using a scrollbar. I tried hiding the scrollbar by setting <span style="font-family:Courier, serif; font-weight:bold;">visibility:hidden</span> on body when scrolling should be disabled but that was weird too. </p>
<p>I would suggest the following 3 alternatives</p>
<ol>
<li>Do <strong>not pin</strong> the Swiper section. Provide a clear UI for horizontal navigation with prev/next buttons and make it clear that swiping is allowed too.</li>
<li>Ditch Swiper. Pin the section and control it with a <a href="https://greensock.com/3-8/#containerAnimation" target="_blank">container animation</a>. Using this technique the scroll-wheel and scrollbar can be used consistently with no lockups or funny business.</li>
<li>Create a full-screen experience where the <strong>scrollbar is always hidden</strong> and the only way to navigate is via scrollwheel or touch gestures. </li>
</ol>
</div>
<div class="brand" style="background:black; text-align:center;"><a href="https://www.creativecodingclub.com/bundles/creative-coding-club?src=cdp3droll" target="_blank"><img src="https://assets.codepen.io/32887/logo-ill.svg" width="300" alt="" /></a></div>
* {
position:relative;
box-sizing:border-box;
}
body, html {
height:100%
}
body {
margin:0;
background:#1d1d1d;
}
li {
margin-top:0.8em;
}
h1, h2 {
margin:0;
}
h1 {
font-size:clamp(200px, 20vw, 20vh);
line-height:0.8em;
}
h2 {
font-size:clamp(30px, 10vw, 6vh);
}
h3 {
padding-top:2em;
margin:0;
}
p, h3, li, h2 {
font-family:sans-serif;
max-width:600px;
}
p, li {
line-height:1.4em;
}
.slideWrapper {
height:50vh;
width:90%;
background:yellow;
}
.swiper {
height:50vh;
width:90%;
margin:auto;
}
.swiper-slide {
text-align: center;
font-size: 18px;
background: #fff;
/* Center slide text vertically */
display: flex;
justify-content: center;
align-items: center;
flex-direction:column;
}
.swiper-slide img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
}
.gray {
background-color: #777;
background-image: radial-gradient(
circle at 47% 14%,
rgba(205, 205, 205, 0.04) 0%,
rgba(205, 205, 205, 0.04) 43%,
transparent 43%,
transparent 100%
),
radial-gradient(
circle at 35% 12%,
rgba(215, 215, 215, 0.04) 0%,
rgba(215, 215, 215, 0.04) 4%,
transparent 4%,
transparent 100%
),
radial-gradient(
circle at 1% 35%,
rgba(24, 24, 24, 0.04) 0%,
rgba(24, 24, 24, 0.04) 37%,
transparent 37%,
transparent 100%
),
radial-gradient(
circle at 21% 1%,
rgba(0, 0, 0, 0.04) 0%,
rgba(0, 0, 0, 0.04) 26%,
transparent 26%,
transparent 100%
),
radial-gradient(
circle at 23% 82%,
rgba(249, 249, 249, 0.04) 0%,
rgba(249, 249, 249, 0.04) 60%,
transparent 60%,
transparent 100%
),
radial-gradient(
circle at 11% 54%,
rgba(251, 251, 251, 0.04) 0%,
rgba(251, 251, 251, 0.04) 23%,
transparent 23%,
transparent 100%
),
radial-gradient(
circle at 69% 68%,
rgba(234, 234, 234, 0.04) 0%,
rgba(234, 234, 234, 0.04) 10%,
transparent 10%,
transparent 100%
),
linear-gradient(90deg, #777, #606060);
}
.blue {
background-color: #2c7ad2;
background-image: radial-gradient(
circle at 47% 14%,
rgba(205, 205, 205, 0.04) 0%,
rgba(205, 205, 205, 0.04) 43%,
transparent 43%,
transparent 100%
),
radial-gradient(
circle at 35% 12%,
rgba(215, 215, 215, 0.04) 0%,
rgba(215, 215, 215, 0.04) 4%,
transparent 4%,
transparent 100%
),
radial-gradient(
circle at 1% 35%,
rgba(24, 24, 24, 0.04) 0%,
rgba(24, 24, 24, 0.04) 37%,
transparent 37%,
transparent 100%
),
radial-gradient(
circle at 21% 1%,
rgba(0, 0, 0, 0.04) 0%,
rgba(0, 0, 0, 0.04) 26%,
transparent 26%,
transparent 100%
),
radial-gradient(
circle at 23% 82%,
rgba(249, 249, 249, 0.04) 0%,
rgba(249, 249, 249, 0.04) 60%,
transparent 60%,
transparent 100%
),
radial-gradient(
circle at 11% 54%,
rgba(251, 251, 251, 0.04) 0%,
rgba(251, 251, 251, 0.04) 23%,
transparent 23%,
transparent 100%
),
radial-gradient(
circle at 69% 68%,
rgba(234, 234, 234, 0.04) 0%,
rgba(234, 234, 234, 0.04) 10%,
transparent 10%,
transparent 100%
),
linear-gradient(90deg, #2c7ad2, #1568c6);
}
.orange {
background-color: #e77614;
background-image: radial-gradient(
circle at 46% 40%,
rgba(228, 228, 228, 0.06) 0%,
rgba(228, 228, 228, 0.06) 13%,
transparent 13%,
transparent 100%
),
radial-gradient(
circle at 11% 41%,
rgba(198, 198, 198, 0.06) 0%,
rgba(198, 198, 198, 0.06) 19%,
transparent 19%,
transparent 100%
),
radial-gradient(
circle at 52% 23%,
rgba(14, 14, 14, 0.06) 0%,
rgba(14, 14, 14, 0.06) 69%,
transparent 69%,
transparent 100%
),
radial-gradient(
circle at 13% 85%,
rgba(148, 148, 148, 0.06) 0%,
rgba(148, 148, 148, 0.06) 44%,
transparent 44%,
transparent 100%
),
radial-gradient(
circle at 57% 74%,
rgba(232, 232, 232, 0.06) 0%,
rgba(232, 232, 232, 0.06) 21%,
transparent 21%,
transparent 100%
),
radial-gradient(
circle at 59% 54%,
rgba(39, 39, 39, 0.06) 0%,
rgba(39, 39, 39, 0.06) 49%,
transparent 49%,
transparent 100%
),
radial-gradient(
circle at 98% 38%,
rgba(157, 157, 157, 0.06) 0%,
rgba(157, 157, 157, 0.06) 24%,
transparent 24%,
transparent 100%
),
radial-gradient(
circle at 8% 6%,
rgba(60, 60, 60, 0.06) 0%,
rgba(60, 60, 60, 0.06) 12%,
transparent 12%,
transparent 100%
),
linear-gradient(90deg, #ff7600, #ff7600);
}
.red {
background-color: #c82736;
background-image: radial-gradient(
circle at 19% 90%,
rgba(190, 190, 190, 0.04) 0%,
rgba(190, 190, 190, 0.04) 17%,
transparent 17%,
transparent 100%
),
radial-gradient(
circle at 73% 2%,
rgba(78, 78, 78, 0.04) 0%,
rgba(78, 78, 78, 0.04) 94%,
transparent 94%,
transparent 100%
),
radial-gradient(
circle at 45% 2%,
rgba(18, 18, 18, 0.04) 0%,
rgba(18, 18, 18, 0.04) 55%,
transparent 55%,
transparent 100%
),
radial-gradient(
circle at 76% 60%,
rgba(110, 110, 110, 0.04) 0%,
rgba(110, 110, 110, 0.04) 34%,
transparent 34%,
transparent 100%
),
radial-gradient(
circle at 68% 56%,
rgba(246, 246, 246, 0.04) 0%,
rgba(246, 246, 246, 0.04) 16%,
transparent 16%,
transparent 100%
),
radial-gradient(
circle at 71% 42%,
rgba(156, 156, 156, 0.04) 0%,
rgba(156, 156, 156, 0.04) 47%,
transparent 47%,
transparent 100%
),
radial-gradient(
circle at 46% 82%,
rgba(247, 247, 247, 0.04) 0%,
rgba(247, 247, 247, 0.04) 39%,
transparent 39%,
transparent 100%
),
radial-gradient(
circle at 50% 47%,
rgba(209, 209, 209, 0.04) 0%,
rgba(209, 209, 209, 0.04) 45%,
transparent 45%,
transparent 100%
),
linear-gradient(90deg, #e53949, #cc2232);
}
.purple {
background-color: #8d3dae;
background-image: radial-gradient(
circle at 47% 14%,
rgba(205, 205, 205, 0.04) 0%,
rgba(205, 205, 205, 0.04) 43%,
transparent 43%,
transparent 100%
),
radial-gradient(
circle at 35% 12%,
rgba(215, 215, 215, 0.04) 0%,
rgba(215, 215, 215, 0.04) 4%,
transparent 4%,
transparent 100%
),
radial-gradient(
circle at 1% 35%,
rgba(24, 24, 24, 0.04) 0%,
rgba(24, 24, 24, 0.04) 37%,
transparent 37%,
transparent 100%
),
radial-gradient(
circle at 21% 1%,
rgba(0, 0, 0, 0.04) 0%,
rgba(0, 0, 0, 0.04) 26%,
transparent 26%,
transparent 100%
),
radial-gradient(
circle at 23% 82%,
rgba(249, 249, 249, 0.04) 0%,
rgba(249, 249, 249, 0.04) 60%,
transparent 60%,
transparent 100%
),
radial-gradient(
circle at 11% 54%,
rgba(251, 251, 251, 0.04) 0%,
rgba(251, 251, 251, 0.04) 23%,
transparent 23%,
transparent 100%
),
radial-gradient(
circle at 69% 68%,
rgba(234, 234, 234, 0.04) 0%,
rgba(234, 234, 234, 0.04) 10%,
transparent 10%,
transparent 100%
),
linear-gradient(90deg, #8d3dae, #8d3dae);
}
.green {
background-color: #28a92b;
background-image: radial-gradient(
circle at 46% 40%,
rgba(228, 228, 228, 0.06) 0%,
rgba(228, 228, 228, 0.06) 13%,
transparent 13%,
transparent 100%
),
radial-gradient(
circle at 11% 41%,
rgba(198, 198, 198, 0.06) 0%,
rgba(198, 198, 198, 0.06) 19%,
transparent 19%,
transparent 100%
),
radial-gradient(
circle at 52% 23%,
rgba(14, 14, 14, 0.06) 0%,
rgba(14, 14, 14, 0.06) 69%,
transparent 69%,
transparent 100%
),
radial-gradient(
circle at 13% 85%,
rgba(148, 148, 148, 0.06) 0%,
rgba(148, 148, 148, 0.06) 44%,
transparent 44%,
transparent 100%
),
radial-gradient(
circle at 57% 74%,
rgba(232, 232, 232, 0.06) 0%,
rgba(232, 232, 232, 0.06) 21%,
transparent 21%,
transparent 100%
),
radial-gradient(
circle at 59% 54%,
rgba(39, 39, 39, 0.06) 0%,
rgba(39, 39, 39, 0.06) 49%,
transparent 49%,
transparent 100%
),
radial-gradient(
circle at 98% 38%,
rgba(157, 157, 157, 0.06) 0%,
rgba(157, 157, 157, 0.06) 24%,
transparent 24%,
transparent 100%
),
radial-gradient(
circle at 8% 6%,
rgba(60, 60, 60, 0.06) 0%,
rgba(60, 60, 60, 0.06) 12%,
transparent 12%,
transparent 100%
),
linear-gradient(90deg, #28a92b, #10a614);
}
const swiper = new Swiper('.swiper', {})
const numPanels = swiper.slides.length;
console.log(numPanels)
// Gsap Code
let currentIndex = 0;
let animating;
swiper.on('slideChange', function () {
currentSlide.textContent = swiper.activeIndex + 1
gsap.to(swiper.slides[swiper.activeIndex], {scale:1, opacity:1})
gsap.to(swiper.slides[swiper.previousIndex], {opacity:0.3, scale:0.8})
swiper.slides[swiper.previousIndex].animation.pause(0)
swiper.slides[swiper.activeIndex].animation.restart()
currentIndex = swiper.activeIndex
});
swiper.on('slideChangeTransitionEnd', function() {
animating = false
})
swiper.slides.forEach((slide, index)=>{
let letter = slide.querySelector("h1")
let description = slide.querySelector("h2")
let chars = SplitText.create(description, {type:"chars"})
let tl = gsap.timeline({paused:true, onComplete:function(){
}})
tl.from(letter, {scale:0, opacity:0, ease:"back", duration:1})
.from(chars.chars, {opacity:0, yPercent:50, stagger:0.02}, "-=0.5")
slide.animation = tl
})
swiper.slides[0].animation.play()
/*
ALL OF THE FOLLOWING CODE IS BORROWED FROM THIS PEN FROM GREENSOCK
https://codepen.io/GreenSock/pen/MWGVJYL?editors=1000
I MADE SLIGHT ALTERATIONS TO MAKE GOTOPANEL() TALK TO SWIPER
*/
// create an observer and disable it to start
let intentObserver = ScrollTrigger.observe({
type: "wheel,touch",
onUp: () => !animating && gotoPanel(currentIndex + 1, true),
onDown: () => !animating && gotoPanel(currentIndex - 1, false),
wheelSpeed: -1, // to match mobile behavior, invert the wheel speed
tolerance: 30,
preventDefault: true,
onPress: self => {
// on touch devices like iOS, if we want to prevent scrolling, we must call preventDefault() on the touchstart (Observer doesn't do that because that would also prevent side-scrolling which is undesirable in most cases)
ScrollTrigger.isTouch && self.event.preventDefault()
}
})
intentObserver.disable();
let preventScroll = ScrollTrigger.observe({
preventDefault: true,
type: "wheel,scroll",
allowClicks: true,
onEnable: self => {
console.log("enable")
return self.savedScroll = self.scrollY()
}, // save the scroll position
onChangeY: self => {
console.log("disable")
self.scrollY(self.savedScroll) // refuse to scroll
}
});
preventScroll.disable();
// handle the panel swipe animations
function gotoPanel(index, isScrollingDown) {
animating = true;
console.log("gotoPanel")
// return to normal scroll if we're at the end or back up to the start
if (
(index === numPanels && isScrollingDown) ||
(index === -1 && !isScrollingDown)
) {
console.log("return to normal scroll")
intentObserver.disable();
preventScroll.disable();
animating = false;
// now make it go 1px beyond in the correct direction so that it doesn't trigger onEnter/onEnterBack.
preventScroll.scrollY(preventScroll.scrollY() + (index === numPanels ? 1 : -1));
return;
}
console.log("call swiper slideTo()")
swiper.slideTo(index)
currentIndex = index;
}
// pin swipe section and initiate observer
ScrollTrigger.create({
trigger: ".gallery",
pin: true,
anticipatePin: true,
start: "top top",
end: "+=50%",
onEnter: (self) => {
if (preventScroll.isEnabled === false) {
self.scroll(self.start);
preventScroll.enable();
intentObserver.enable();
gotoPanel(currentIndex + 1, true);
}
},
onEnterBack: (self) => {
if (preventScroll.isEnabled === false) {
self.scroll(self.start);
preventScroll.enable();
intentObserver.enable();
gotoPanel(currentIndex - 1, false);
}
}
});
ScrollTrigger.config({
ignoreMobileResize: true
});
Also see: Tab Triggers