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 id="app">
<!-- 时间线 -->
<div class="timeline" ref="timeline">
<div v-for="date in timeline" class="time" :key="date.year">
<div
v-for="month in date.months"
:class="[
'month',
currTime === `${date.year}-${month}` ? 'active' : ''
]"
:key="date.year + '-' + month"
ref="month-block"
:date="date.year + '-' + month"
@click="toMonth(date.year, month)"
>
{{ month }}
</div>
<div class="year">{{ date.year }}</div>
</div>
</div>
<!-- 右侧内容 -->
<div class="main" ref="main">
<div class="wrap" ref="wrap" @scroll="scrollSpyNav">
<div
class="month-detail"
ref="month-detail"
v-for="month in sourceData"
:key="month.date"
:date="month.date"
>
<h3>{{ month.date.split("-")[1] }}月</h3>
<div class="container">
<div class="row">
<div class="col col-12">
签约数:
<span>{{ month.detail.total }}</span>
</div>
<div class="col col-6">
A类:
<span>{{ month.detail.a }}</span>
</div>
<div class="col col-6">
B类:
<span>{{ month.detail.b }}</span>
</div>
<div class="col col-6 offset-6">
总设备数:
<span>{{ month.detail.machines }}</span>
</div>
</div>
</div>
<a class="more" href="#">查看当月明细</a>
</div>
</div>
</div>
</div>
.timeline
width 80px
height 80%
text-align center
background #f6f6f6
border-top-left-radius 5px
border-top-right-radius 25px
display flex
flex-direction column
position absolute
left 0
bottom 0
z-index 10
overflow-x hidden
box-sizing border-box
&::-webkit-scrollbar-thumb, &::-webkit-scrollbar
display none
.time
&:first-child
padding-top 50px
div
width 80%
height 60px
line-height @height
font-size 25px
font-weight bold
transition all .4s
.year
width 100%
color #969696
background #e0e0e0
position sticky
bottom 0
.month
color #dcdcdc
border-top #dadada 1px solid
margin 0 auto
position relative
cursor pointer
&:first-child
border-top 0
&.active
color #656565
&:after
content 'month'
width 100%
height 20px
line-height @height
font-size 12px
font-weight normal
text-transform uppercase
display block
position absolute
left 0
bottom 4px
// 右侧主体内容
.main
width 100%
height 100%
background white
padding 50px 0 0 80px
border-top-left-radius 45px
border-top-right-radius 5px
margin-left auto
.wrap
width 100%
height 100%
padding-bottom 50px
overflow-x hidden
.month-detail
padding 10px 0
h3
height 45px
line-height @height
font-size 24px
font-weight bold
border-bottom #dfdfdf 1px solid
margin-bottom 15px
div
line-height 30px
color #ababab
span
color #333
.more
font-size 12px
color #4c6486
text-align center
text-decoration none
padding 15px 0
margin -10px auto
display block
/*
* defalut
*/
#app
width 100%
max-width 600px
height 100%
background #333
padding 80px 0 0 35px
margin 0 auto
position relative
box-sizing border-box
html,body
width 100%
height 100%
background gray
::-webkit-scrollbar-thumb
background #333
border-radius 3px
::-webkit-scrollbar
width 5px
background none
::-webkit-scrollbar-track
::-webkit-scrollbar-button
::-webkit-scrollbar-track-piece
width 0
height 0
background none
var app = new Vue({
el: '#app',
computed: {
timeline() {
let list = [];
const data = this.sourceData;
if (!data) return list;
data.forEach(item => {
const date = item.date.split("-");
const year = list.find(item => item.year === date[0]);
if (year) {
year.months.push(date[1]);
} else {
list.push({
year: date[0],
months: [date[1]]
});
}
});
return list;
},
offsetList() {
const list = this.$refs["month-detail"];
let data = list.map(el => {
return {
date: el.getAttribute("date"),
offset: el.offsetTop - 100
};
});
return data;
}
},
watch: {
currTime() {
this.scrollTimeline();
}
},
mounted() {
this.currTime = this.sourceData[0].date;
},
methods: {
// 跳转到对应月份
toMonth(year, month) {
this.currTime = `${year}-${month}`;
const detailItem = this.offsetList.find(
item => item.date === this.currTime
);
this.$refs["wrap"].scrollTo({
top: detailItem.offset,
behavior: "smooth"
});
},
// 滚动左侧时间线
scrollTimeline() {
const el = this.$refs["month-block"].find(
item => item.getAttribute("date") === this.currTime
);
this.$refs["timeline"].scrollTo({
top: el.offsetTop - 50,
behavior: "smooth"
});
},
// 滚动侦测导航
scrollSpyNav(e) {
clearTimeout(this.timer);
const offsetTop = e.target.scrollTop;
const curr = this.offsetList.find(item => item.offset >= offsetTop);
this.timer = window.setTimeout(() => {
this.currTime = curr.date;
}, 300);
}
},
data() {
return {
sourceData: [
{
date: "2020-01",
detail: {
a: 100,
b: 78,
total: 178,
machines: 967
},
note: "some text of 2020-01"
},
{
date: "2019-12",
detail: {
a: 100,
b: 78,
total: 178,
machines: 967
},
note: "some text of 2019-12"
},
{
date: "2019-11",
detail: {
a: 100,
b: 78,
total: 178,
machines: 967
},
note: "some text of 2019-11"
},
{
date: "2019-10",
detail: {
a: 100,
b: 78,
total: 178,
machines: 967
},
note: "some text of 2019-10"
},
{
date: "2019-09",
detail: {
a: 100,
b: 78,
total: 178,
machines: 967
},
note: "some text of 2019-09"
},
{
date: "2019-08",
detail: {
a: 100,
b: 78,
total: 178,
machines: 967
},
note: "some text of 2019-08"
},
{
date: "2019-07",
detail: {
a: 100,
b: 78,
total: 178,
machines: 967
},
note: "some text of 2019-07"
},
{
date: "2019-06",
detail: {
a: 100,
b: 78,
total: 178,
machines: 967
},
note: "some text of 2019-06"
},
{
date: "2019-05",
detail: {
a: 100,
b: 78,
total: 178,
machines: 967
},
note: "some text of 2019-05"
},
{
date: "2019-04",
detail: {
a: 100,
b: 78,
total: 178,
machines: 967
},
note: "some text of 2019-04"
},
{
date: "2019-03",
detail: {
a: 100,
b: 78,
total: 178,
machines: 967
},
note: "some text of 2019-03"
},
{
date: "2019-02",
detail: {
a: 100,
b: 78,
total: 178,
machines: 967
},
note: "some text of 2019-02"
},
{
date: "2019-01",
detail: {
a: 100,
b: 78,
total: 178,
machines: 967
},
note: "some text of 2019-01"
},
{
date: "2018-12",
detail: {
a: 100,
b: 78,
total: 178,
machines: 967
},
note: "some text of 2018-12"
}
],
timer: null,
currTime: ""
};
}
})
Also see: Tab Triggers