div+css实现粘性带进度显示导航条滚动效果代码

代码语言:html

所属分类:加载滚动

代码描述:div+css实现粘性带进度显示导航条滚动效果代码,上方导航显示滚动的进度,点击可滚动到相关页面,全程无js代码实现。

代码标签: div css 粘性 进度 显示 导航 滚动

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  

  
  
  
<style>
@import url('https://fonts.googleapis.com/css2?family=Varela+Round&display=swap');

:root {
	--black: #373737;
	--sect1: #ff9900;
	--sect2: #2196F3;
	--sect3: #e63232;
	--sect4: #8BC34A;
	--sect5: #8946ff;
}

* { 
	box-sizing: border-box; 
}

html {
	scroll-behavior: smooth;
}

body {
	margin: 0;
	padding: 0;
	transition: all 0.5s ease 0s;
	font-family: 'Varela Round', cursive;
}

body:after {
	content: "Progress Bar only in Chrome";
	position: fixed;
	bottom: 0;
	width: 100%;
	text-align: center;
	color: var(--black);
	font-size: 1rem;
	padding: 20px 0;
}

header {
	width: 100%;
}

nav {
	top: 0;
	left: 0;
	position: fixed;
	width: 100%;
	height: 65px;
	background: linear-gradient(0deg, #fff0 0px, var(--black) 1px 100%);
	text-align: center;
	display: flex;
	transition: all 0.5s ease 0s;
}

nav a {
	color: #fff;
	text-decoration: none;
	padding: 16px 10px;
	position: relative;
	z-index: 1;
	width: 100%;
	font-size: 1.6rem;
	border: 2px solid #000;
	border-top-width: 0px;
	border-bottom-width: 4px;
}

nav a:first-child {
	border-left-width: 0;
}

nav a:last-child {
	border-right-width: 0;
}

nav a:hover {
	background: linear-gradient(90deg, var(--clr) 0 50%, var(--black) 0 100%);
	background-size: 200%;
	background-position: 100% 0;
	animation: colorize 0.5s ease 0s;
	animation-fill-mode: forwards;
	transition: all 0.5s ease 0s;
}

@keyframes colorize {
	100% { background-position: 0 0; }
}

nav a:nth-child(1):hover {
	--clr: var(--sect1);
}
nav a:nth-child(2):hover {
	--clr: var(--sect2);
}
nav a:nth-child(3):hover {
	--clr: var(--sect3);
}
nav a:nth-child(4):hover {
	--clr: var(--sect4);
}
nav a:nth-child(5):hover {
	--clr: var(--sect5);
}


nav:after {
	content: "";
	position: absolute;
	bottom: 0;
	left: 0;
	width: 20vw;
	width: 20%;
	height: 100%;
	z-index: -1;
	background: linear-gradient(90deg, var(--sect1) 0 calc(20vw - 3px), var(--sect2) 0 calc(40vw - 6px), var(--sect3) 0 calc(60vw - 10px), var(--sect4) 0 calc(80vw - 13px), var(--sect5) 0 100vw);
	animation: progress linear;
	animation-timeline: scroll(root);
}

@keyframes progress {
	100% { width: 100%; }
}



/*** SECTIONS ***/
section {
	height: 100vh;
	justify-content: center;
	align-items: center;
	font-size: 4rem;
	color: #fff;
	padding-top: 30px;
	border-bottom: 4px solid #000;
	display: flex;
	flex-wrap: wrap;
	align-content: center;
}

section h2, section p {
	margin: 0;
	width: 100%;
	text-align: cent.........完整代码请登录后点击上方下载按钮下载查看

网友评论0