js实现滚动数字变化动画效果代码
代码语言:html
所属分类:加载滚动
代码描述:js实现滚动数字变化动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<link rel='stylesheet' href='https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,700;1,400;1,700&family=Source+Sans+Pro:wght@400;700&display=swap'>
<style>
.stat {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
flex-grow: 1;
/* font matters a good deal here, esp the width of the numerals */
font-family: "Source Sans Pro", serif;
}
.stat-figure {
font-size: 3em;
display: flex;
font-weight: bold;
}
.stat-caption {
text-align: center;
}
/* Demo styling only */
:root {
--color-background: teal;
--color-text: #f6fde1;
--color-accent: #faff98;
--gap: clamp(1rem, 6vw, 3rem);
--full: minmax(var(--gap), 1fr);
--content: min(30em, 100% - var(--gap) * 2);
--popout: minmax(0, 3rem);
}
/* Forced reset */
*, *:before, *:after {
margin: 0;
padding: 0;
}
body {
font-family: 'Lora', serif;
background-color: var(--color-background);
color: var(--color-text);
font-size: clamp(1.125rem, 0.625vw + 0.875rem, 1.625rem);
line-height: 1.25;
}
h1, h2, h3, h4 {
color: var(--color-accent);
font-family: 'Source Sans Pro', sans-serif;
}
.text-reverse {
padding: 3ch;
background-color: var(--color-text);
color: var(--color-background);
border-radius: 2ch;
}
/* Simple grid with popout */
.grid {
display: grid;
grid-template-columns:
[full-start] var(--full)
[popout-start] var(--popout)
[content-start] var(--content) [content-end]
var(--popout) [popout-end]
var(--full) [full-end];
}
.grid > * {
grid-column: content;
}
.popout {
grid-column: popout;
}
/* Simple vertical rhythm */
.flow > * + * {
margin-top: var(--flow, 1em)
}
.flex {
display: flex;
}
.gap {
gap: 2ch;
}
.mb-10vh {
margin-bottom: 10vh;
}
</style>
</head>
<body >
<article class="grid flow mb-10vh">
<h1>Animated Number Counter on Scroll w/Vanilla Javascript</h1>
<div class="popout flow text-reverse">
<p>These numbers will count up from 0 when they enter the viewport, making a small statement from an otherwise static number. This has a slight easing applied and will properly format decimals and commas thanks to .toLocaleString().</p>
</div>
<div class="flex gap popout" data-module="countup".........完整代码请登录后点击上方下载按钮下载查看
网友评论0