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.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#2d7cd1">
<title>mode-test</title>
<meta name="mobile-web-app-capable" content="yes">
</head>
<body>
<article class="mode typeF T1M1" data-gsap="animation-13">
<section>
<!-- 圖片背景灰色裝飾 滿版 -->
<!-- 圖 -->
<div class="full-bg cover">
<div class="mode-inner">
<div class="mode-images">
<div class="mode-images-inner">
<img src="https://picsum.photos/1920/1200" alt="">
</div>
</div>
</div>
</div>
<!-- 文 -->
<div class="mode-inner">
<div class="mode-text">
<div class="mode-text-inner">
<div class="text-num-1">
<!-- 英文標題(橫式)-->
<p class="text-engName textWrap">
<span class="textUp">
Tokyo Tower
</span>
</p>
<!-- 中文標題 -->
<h2 class="text-twName-title textWrap">
<span class="textUp">
東京鐵塔
</span>
</h2>
</div>
<div class="text-num-2">
<!-- 概括 -->
<p class="text-twName-summary">
<span>
東京鐵塔是位於日本東京都的知名景點。
</span>
</p>
<!-- 內文 -->
<p class="text-content">
<span>
獨特的地理構造使其形成了曠世奇絕的自然景觀;它以彩池、雪山、峽谷、森林「四絕」著稱於世。壯觀的地表鈣華流蜿蜒於原始林海,酷似一條金色巨龍,騰遊天地,故名黃龍。黃龍風景區的數千個鈣華彩池形態各異,流光泛彩,長達2500公尺的鈣華流是世界之最。(0/130)
</span>
</p>
</div>
</div>
</div>
</div>
</section>
</article>
<article class="mode typeF T1M1 inner" data-gsap="animation-14">
<section>
<!-- 圖片背景灰色裝飾 滿版 -->
<div class="full-bg">
<div class="mode-inner">
<!-- 文 -->
<div class="mode-text">
<div class="mode-text-inner">
<!-- 英文標題(橫式)-->
<p class="text-engName textWrap">
<span class="textUp">
Tokyo Tower
</span>
</p>
</div>
</div>
<!-- 圖 -->
<div class="mode-images">
<div class="mode-images-inner">
<div class="images-decorate">
<div class="images-cut">
<img src="https://picsum.photos/id/25/900/600" alt="">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="mode-inner">
<!-- 文 -->
<div class="mode-text text-on-banner">
<div class="mode-text-inner">
<!-- 中文標題 -->
<h2 class="text-twName-title">
<span>
東京鐵塔
</span>
</h2>
<!-- 概括 -->
<p class="text-twName-summary">
<span>
東京鐵塔是位於日本東京都的知名景點。
</span>
</p>
<!-- 內文 -->
<p class="text-content">
<span>
都江堰水利工程是由秦國蜀郡守李冰為治理岷江水患率眾修建的大型水利工程,其工程採用無霸引水的形式,主要由魚水分水堤,飛沙堰溢洪道,寶瓶引水口三大主體工程組成。巧妙地利用了岷江出口的天然地勢和彎道水流規律,有效地解決了引水灌溉、洩洪排沙的問題構成了一套科學完整的自(0/130)
</span>
</p>
</div>
</div>
</div>
</section>
</article>
<article class="mode typeA T1M2 column" data-gsap="animation-19">
<section class="mode-inner">
<!-- 英文標題 (直式)-->
<p class="text-engName-column textWrap">
<span class="textDown">
Traveling to tokyo japan
</span>
</p>
<!-- 圖文 -->
<div class="mode-text mode-images">
<div>
<div class="mode-images-inner">
<div class="">
<div class="">
<img src="https://picsum.photos/id/13/900/600" alt="">
</div>
</div>
</div>
<div class="mode-images-inner">
<div class="images-decorate">
<div class="">
<img src="https://picsum.photos/id/13/900/600" alt="">
</div>
</div>
</div>
</div>
<div>
<div class="mode-text-inner">
<!-- 英文標題(橫式)-->
<p class="text-engName textWrap">
<span class="textUp">
Tokyo Tower
</span>
</p>
<!-- 中文標題 -->
<h2 class="text-twName-title textWrap">
<span class="textUp">
東京鐵塔
</span>
</h2>
<!-- 概括 -->
<p class="text-twName-summary textWrap">
<span class="textUp">
東京鐵塔是位於日本東京都的知名景點。
</span>
</p>
<!-- 內文 -->
<p class="text-content">
<span>
【錦里古街】,成都人則會用2塊錢喝茶、3塊錢吃飯、5塊錢打麻將。雖說這樣有趣的比喻不能完全涵蓋這三個地域人們的生活文化,民風民情,但這也勾勒出了成都人幸福、知足,平和、會生活的另一面。去錦裏「趕場」是成都市民們休閒遊玩的最佳選擇。走進錦裏,青石板鋪就的小路蜿蜒前行,淺灰色的青磚砌牆,各式老街、宅邸、府第、客棧、商鋪、座落其間,青瓦錯落有致,欣賞這些古色古香的建築,走在這清末民初的四川古鎮建築中感受到時空變換的神奇。可充分體驗四川民俗的獨特魅力,對蜀漢文和古成都風貌有更深入的瞭(0/260)
</span>
</p>
</div>
</div>
</div>
</section>
</article>
<article class="mode typeA T1M3" data-gsap="animation-15">
<section class="mode-inner">
<!-- 圖文 -->
<div class="mode-text mode-images">
<!-- 圖1 -->
<div class="mode-images-inner images-num-1">
<img src="https://picsum.photos/id/1/900/600" alt="">
</div>
<!-- 文 -->
<div class="mode-text-inner">
<div class="text-num-1">
<!-- 英文標題(橫式)-->
<p class="text-engName textWrap">
<span class="textUp">
Tokyo Tower
</span>
</p>
<!-- 中文標題 -->
<h2 class="text-twName-title textWrap">
<span class="textUp">
東京鐵塔
</span>
</h2>
<!-- 概括 -->
<p class="text-twName-summary textWrap">
<span class="textUp">
東京鐵塔是位於日本東京都的知名景點。
</span>
</p>
</div>
<div class="text-num-2">
<!-- 內文 -->
<p class="text-content">
<span>
寬窄巷子歷經近300年的變遷留給老成都的歲月痕跡依然依稀可見。現代化賦予了老巷子新的時代精神,但老巷子中所蘊含的老成都生活精神,依然是現今成都人生生不息的休閒精神的源泉。在寬窄巷子的翻修過程中,專門用一個院落打造了“成都原真生活體驗館”,展示寬窄巷子的平民魅。生活體驗館”,展示寬窄巷子的平民魅。(0/150)
</span>
</p>
</div>
</div>
<!-- 圖2 -->
<div class="mode-images-inner images-num-2">
<img src="https://picsum.photos/id/1/900/600" alt="">
</div>
</div>
<!-- 圖 -->
<div class="mode-images">
<!-- 圖3 -->
<div class="mode-images-inner images-num-3">
<img src="https://picsum.photos/id/1/900/600" alt="">
</div>
</div>
</section>
</article>
<article class="mode typeA T1M3 reverse" data-gsap="animation-16">
<section class="mode-inner">
<!-- 圖文 -->
<div class="mode-text mode-images">
<!-- 圖1 -->
<div class="mode-images-inner images-num-1">
<img src="https://picsum.photos/900/600" alt="">
</div>
<!-- 文 -->
<div class="mode-text-inner">
<div class="text-num-1">
<!-- 英文標題(橫式)-->
<p class="text-engName textWrap">
<span class="textUp">
Tokyo Tower
</span>
</p>
<!-- 中文標題 -->
<h2 class="text-twName-title textWrap">
<span class="textUp">
東京鐵塔
</span>
</h2>
<!-- 概括 -->
<p class="text-twName-summary textWrap">
<span class="textUp">
東京鐵塔是位於日本東京都的知名景點。
</span>
</p>
</div>
<div class="text-num-2">
<!-- 內文 -->
<p class="text-content">
<span>
寬窄巷子歷經近300年的變遷留給老成都的歲月痕跡依然依稀可見。現代化賦予了老巷子新的時代精神,但老巷子中所蘊含的老成都生活精神,依然是現今成都人生生不息的休閒精神的源泉。在寬窄巷子的翻修過程中,專門用一個院落打造了“成都原真生活體驗館”,展示寬窄巷子的平民魅。生活體驗館”,展示寬窄巷子的平民魅。(0/150)
</span>
</p>
</div>
</div>
<!-- 圖2 -->
<div class="mode-images-inner images-num-2">
<img src="https://picsum.photos/900/600" alt="">
</div>
</div>
<!-- 圖 -->
<div class="mode-images">
<!-- 圖3 -->
<div class="mode-images-inner images-num-3">
<img src="https://picsum.photos/900/600" alt="">
</div>
</div>
</section>
</article>
</body>
</html>
// GSAP系列模組 個別動畫 start ---------------------------------
// 統整所有模組個別動畫
gsap.registerPlugin(ScrollTrigger, ScrollToPlugin);
let mode = document.querySelectorAll(".mode");
function modeAnimation() {
mode.forEach(e => {
let tar;
let tar2;
let tar3;
let tar4;
let tar5;
let tl;
let mq = window.matchMedia("(max-width: 991px)");
let mq2 = window.matchMedia("(max-width: 767px)");
switch (e.getAttribute("data-gsap")) {
case "animation-13":
// 動畫模組:mode typeF T1M1
tar = e.querySelector(".typeF.T1M1 .mode-images");
tar2 = e.querySelector(".typeF.T1M1 .mode-text .mode-text-inner .text-num-1");
tar3 = e.querySelector(".typeF.T1M1 .mode-text .mode-text-inner .text-num-2");
if (mq2.matches) {
tl = gsap.timeline()
.from(tar, {
scale: 1.5,
duration: 3,
delay: 1,
ease: Power1.easeIn,
transformOrigin: "50% 0%",
scrub: 1,
})
.from(tar2, {
yPercent: -100,
ease: Power1.easeIn,
scale: 1.5,
duration: 3,
transformOrigin: "50% 50%",
scrub: 1,
opacity: 0,
},">-1")
.from(tar3, {
opacity: 0,
scrub: 1,
},">");
ScrollTrigger.create({
trigger: e,
pin: true,
pinSpacing: true,
anticipatePin: true,
ease: Power1.easeIn,
start: "top 10%",
end: "+=600",
scrub: 0,
once: true,
animation: tl,
onLeave: function (self) {
self.scroll(self.start);
self.disable();
self.animation.progress(1);
ScrollTrigger.refresh();
},
});
} else {
tl = gsap.timeline()
.from(tar2, {
yPercent: -280,
ease: Power1.easeIn,
scale: 2,
duration: 5,
scrub: 1,
})
.from(tar, {
yPercent: 280,
scale: 3,
duration: 5,
ease: Power1.easeIn,
scrub: 1,
},">-4")
.from(tar3, {
opacity: 0,
duration: 3,
scrub: 1,
},">");
ScrollTrigger.create({
trigger: e,
pin: true,
pinSpacing: true,
anticipatePin: true,
ease: Power1.easeIn,
start: "top top",
end: "+=1500",
scrub: 0,
once: true,
animation: tl,
onLeave: function (self) {
self.scroll(self.start);
self.disable();
self.animation.progress(1);
ScrollTrigger.refresh();
},
});
};
break;
case "animation-14":
// 動畫模組:mode typeF T1M1 inner
tar = e.querySelector('.typeF.T1M1.inner .text-on-banner');
tl = gsap.timeline()
.from(tar, {
xPercent: 50,
duration: 1,
ease: Power1.easeIn,
opacity: 0,
scrub: 1,
});
ScrollTrigger.create({
trigger: e,
start: "center center",
end: "+=1000",
pin: true,
pinSpacing: true,
anticipatePin: true,
scrub: 0,
once: true,
animation: tl,
onLeave: function (self) {
self.scroll(self.start);
self.disable();
self.animation.progress(1);
ScrollTrigger.refresh();
},
});
break;
case "animation-15":
// 動畫模組:mode typeA T1M3
tar = e.querySelector(".typeA.T1M3 .text-num-1");
tar2 = e.querySelector(".typeA.T1M3 .text-num-2");
tar3 = e.querySelector(".typeA.T1M3 .images-num-1");
tar4 = e.querySelector(".typeA.T1M3 .images-num-2");
tar5 = e.querySelector(".typeA.T1M3 .images-num-3");
if (mq.matches) {
tl = gsap.timeline()
.fromTo(tar, {
opacity: 0,
yPercent: -100,
},{
start: "center center",
end: "+=300",
scrub: 1,
opacity: 1,
duration: 1,
yPercent: 0,
},"-=4")
.fromTo(tar3, {
xPercent: 80,
yPercent: 100,
opacity: 0,
scale: 1.3,
transformOrigin: "50% 50%",
zIndex:1,
},{
ease: Power1.easeIn,
start: "center 70%",
end: "+=200",
scrub: 1,
opacity: 1,
scale: 1,
duration: 1,
xPercent: 0,
yPercent: 0,
},">")
.fromTo(tar4, {
xPercent: -120,
yPercent: -250,
opacity: 0,
scale: 0.7,
transformOrigin: "50% 50%",
},{
ease: Power1.easeIn,
start: "bottom 70%",
end: "+=200",
scrub: 1,
opacity: 1,
scale: 1,
duration: 1,
xPercent: 0,
yPercent: 0,
},"<")
.fromTo(tar5, {
xPercent: 150,
yPercent: -350,
opacity: 0,
scale: 0.75,
transformOrigin: "50% 50%",
},{
ease: Power1.easeIn,
start: "bottom 80%",
end: "+=200",
scrub: 1,
opacity: 1,
scale: 1,
duration: 1,
xPercent: 0,
yPercent: 0,
},"<")
.fromTo(tar2, {
opacity: 0,
},{
ease: Power1.easeIn,
start: "bottom 80%",
end: "+=200",
scrub: 1,
opacity: 1,
duration: 1,
},">-=1");
ScrollTrigger.create({
trigger: e,
pin: true,
pinSpacing: true,
anticipatePin: true,
start: "top top",
end: "+=1200",
scrub: 0,
once: true,
animation: tl,
onLeave: function (self) {
self.scroll(self.start);
self.disable();
self.animation.progress(1);
ScrollTrigger.refresh();
},
});
} else {
tl = gsap.timeline()
.fromTo(tar, {
scale: 2,
opacity: 1,
},{
start: "center center",
end: "+=600",
scrub: 1,
scale: 1,
duration: 1.5,
})
.fromTo(tar3, {
xPercent: 100,
yPercent: 50,
opacity: 0,
scale: 1.3,
delay: 1,
zIndex:1,
},{
ease: Power1.easeIn,
start: "center 70%",
end: "+=200",
scrub: 1,
opacity: 1,
scale: 1,
duration: 1.5,
xPercent: 0,
yPercent: 0,
},">-=1")
.fromTo(tar4, {
xPercent: -100,
yPercent: 30,
opacity: 0,
scale: 0.7,
delay: 1,
},{
ease: Power1.easeIn,
start: "bottom 70%",
end: "+=400",
scrub: 1,
opacity: 1,
scale: 1,
duration: 1.5,
xPercent: 0,
yPercent: 0,
},"<+=25%")
.fromTo(tar5, {
xPercent: 30,
yPercent: -70,
opacity: 0,
scale: 0.75,
delay: 1,
transformOrigin: "50% 50%",
},{
ease: Power1.easeIn,
start: "bottom 80%",
end: "+=400",
scrub: 1,
opacity: 1,
scale: 1,
duration: 1.5,
xPercent: 0,
yPercent: 0,
},"<+=25%")
.fromTo(tar2, {
yPercent: -10,
opacity: 0,
delay: 1,
},{
ease: Power1.easeIn,
start: "bottom 80%",
end: "+=400",
scrub: 1,
yPercent: 0,
opacity: 1,
},">-=1");
ScrollTrigger.create({
trigger: e,
pin: true,
pinSpacing: true,
anticipatePin: true,
start: "center 60%",
end: "+=1200",
scrub: 0,
once: true,
animation: tl,
onLeave: function (self) {
self.scroll(self.start);
self.disable();
self.animation.progress(1);
ScrollTrigger.refresh();
},
});
};
break;
case "animation-16":
// 動畫模組:mode typeA T1M3 reverse
tar = e.querySelector(".typeA.T1M3.reverse .text-num-1");
tar2 = e.querySelector(".typeA.T1M3.reverse .text-num-2");
tar3 = e.querySelector(".typeA.T1M3.reverse .images-num-1");
tar4 = e.querySelector(".typeA.T1M3.reverse .images-num-2");
tar5 = e.querySelector(".typeA.T1M3.reverse .images-num-3");
if (mq.matches) {
tl = gsap.timeline()
.fromTo(tar, {
opacity: 0,
yPercent: -100,
},{
start: "center center",
end: "+=300",
scrub: 1,
opacity: 1,
duration: 1,
yPercent: 0,
},"-=4")
.fromTo(tar3, {
xPercent: -80,
yPercent: 100,
opacity: 0,
scale: 1.3,
transformOrigin: "50% 50%",
zIndex:1,
},{
ease: Power1.easeIn,
start: "center 70%",
end: "+=200",
scrub: 1,
opacity: 1,
scale: 1,
duration: 1,
xPercent: 0,
yPercent: 0,
},">")
.fromTo(tar4, {
xPercent: -120,
yPercent: -250,
opacity: 0,
scale: 0.7,
transformOrigin: "50% 50%",
},{
ease: Power1.easeIn,
start: "bottom 70%",
end: "+=200",
scrub: 1,
opacity: 1,
scale: 1,
duration: 1,
xPercent: 0,
yPercent: 0,
},"<")
.fromTo(tar5, {
xPercent: 150,
yPercent: -350,
opacity: 0,
scale: 0.75,
transformOrigin: "50% 50%",
},{
ease: Power1.easeIn,
start: "bottom 80%",
end: "+=200",
scrub: 1,
opacity: 1,
scale: 1,
duration: 1,
xPercent: 0,
yPercent: 0,
},"<")
.fromTo(tar2, {
opacity: 0,
},{
ease: Power1.easeIn,
start: "bottom 80%",
end: "+=200",
scrub: 1,
opacity: 1,
duration: 1,
},">-=1");
ScrollTrigger.create({
trigger: e,
pin: true,
pinSpacing: true,
anticipatePin: true,
start: "top top",
end: "+=1200",
scrub: 0,
once: true,
animation: tl,
onLeave: function (self) {
self.scroll(self.start);
self.disable();
self.animation.progress(1);
ScrollTrigger.refresh();
},
});
} else {
tl = gsap.timeline()
.fromTo(tar, {
scale: 2,
opacity: 1,
},{
start: "center center",
end: "+=600",
scrub: 1,
scale: 1,
duration: 1.5,
})
.fromTo(tar3, {
xPercent: -100,
yPercent: 50,
opacity: 0,
scale: 1.3,
delay: 1,
zIndex:1,
},{
ease: Power1.easeIn,
start: "center 70%",
end: "+=200",
scrub: 1,
opacity: 1,
scale: 1,
duration: 1,
xPercent: 0,
yPercent: 0,
},">-=1")
.fromTo(tar4, {
xPercent: 100,
yPercent: 30,
opacity: 0,
scale: 0.7,
delay: 1,
},{
ease: Power1.easeIn,
start: "bottom 70%",
end: "+=400",
scrub: 1,
opacity: 1,
scale: 1,
duration: 1,
xPercent: 0,
yPercent: 0,
},"<+=25%")
.fromTo(tar5, {
xPercent: -30,
yPercent: -70,
opacity: 0,
scale: 0.75,
delay: 1,
transformOrigin: "50% 50%",
},{
ease: Power1.easeIn,
start: "bottom 80%",
end: "+=400",
scrub: 1,
opacity: 1,
scale: 1,
duration: 1,
xPercent: 0,
yPercent: 0,
},"<+=25%")
.fromTo(tar2, {
yPercent: -10,
opacity: 0,
delay: 1,
},{
ease: Power1.easeIn,
start: "bottom 80%",
end: "+=400",
scrub: 1,
yPercent: 0,
opacity: 1,
},">-=1");
ScrollTrigger.create({
trigger: e,
pin: true,
pinSpacing: true,
anticipatePin: true,
start: "center 60%",
end: "+=1200",
scrub: 0,
once: true,
animation: tl,
onLeave: function (self) {
self.scroll(self.start);
self.disable();
self.animation.progress(1);
ScrollTrigger.refresh();
},
});
};
break;
case "animation-19":
// 動畫模組:mode typeA T1M2 column
tar = e.querySelectorAll('.typeA.T1M2.column .mode-text.mode-images .mode-images-inner')[0];
tar2 = e.querySelectorAll('.typeA.T1M2.column .mode-text.mode-images .mode-images-inner')[1];
gsap.from(tar, {
scrollTrigger: {
trigger: e,
toggleActions: "play pause resume reset",
},
yPercent: -15,
ease: Power1.easeIn,
opacity: 0,
scrub: 1,
start: "20% bottom",
end: "+=300",
});
gsap.from(tar2, {
scrollTrigger: {
trigger: e,
toggleActions: "play pause resume reset",
},
yPercent: 15,
ease: Power1.easeIn,
opacity: 0,
scrub: 1,
start: "20% bottom",
end: "+=300",
});
break;
};
// end switch
});
};
mode.length >= 1 ? modeAnimation() : "";
// GSAP系列模組 個別動畫 end ---------------------------------
Also see: Tab Triggers