js+css实现古老画卷打开页面内容顺滑滚动导航效果代码

代码语言:html

所属分类:加载滚动

代码描述:js+css实现古老画卷打开页面内容顺滑滚动导航效果代码,点击上次的导航顺滑滚动到页面的不同内容处。

代码标签: js css 古老 画卷 打开 页面 内容 顺滑 滚动 导航

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

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

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

  
  
  
<style>
@import url('https://fonts.googleapis.com/css2?family=Pirata+One&family=Tilt+Neon&display=swap');
*,
::before,
::after {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
html{
scroll-behavior: smooth;
}
body {
  min-height: 100svh;
  background-color: rgb(252, 251, 235);
  font-family: system-ui;
  line-height: 1.4;
  font-size: 1rem;
}
h1,h2{
  font-size: 2.4rem;
  font-family: "Pirata One", system-ui;
  margin-bottom: 1rem;
}
h2{
  font-size: 1.7rem;
}
p + p {
  margin-top: 1rem;
}
header{
  position: fixed;
  top: 0;
  width: 100%;
  z-index: 999;
  background-color: rgba(3, 41, 77, 0.9);
  backdrop-filter: blur(5px);
  display: flex;
  flex-direction: column;
align-items: center;
  gap: 1rem;
  padding: 1rem;
  color: #FFF;
}
nav {
   font-family: "Pirata One", system-ui;
  font-size: 1.8rem;
  display: flex;
  gap: 2rem;
  justify-content: center;
  
  
}
nav > a {
  color: #fff;
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: 10px;
  transition: background-color 300ms ease-in-out;
}
nav > a:hover {
   background-color: rgb(170, 103, 14);
}
.hashtag {
	font-size: 0.8rem;
	font-weight: 300;
	text-align: right;
}
.hashtag a{
  display: block;
  color:#FFF;
  text-align: center;
}
.hashtag a:hover{
  color: #EAB308;
}

section {
  height: 100svh; /* each section has 100% screen height to avoid flicker when closeing*/
  display: grid;
  place-content: center; /* place the scroll in the center of each section */
  scroll-behavior: smooth;
  padding-top: 6rem;
}

article {
  --_width: 600px; /* all the scroll elements will have the same width */

  width: var(--_width);
  position: relative;
  display: grid;
  grid-template-rows: 0px; /* set to 0px initally to hide the scroll contents */
  transition: grid-template-rows 500ms ease-in-out;
}

/* place the top part of the scroll as a pseudo element on the article */
article::before {
  content: "";
  position: absolute;
  left: 0;
  top: -92px;
  width: 100%;
  height: 93px;
  background-image: url(//repo.bfw.wiki/bfwrepo/images/huajuan/scroll-top.png);
  background-repeat: no-repeat;
  background-position: center;
  background-size: 600px;
  z-index: 10;
}

/* 
wrapper to hide the contents for the grid rows transition
This also holds the bottom of the scroll so that it is pushed down 
 */
article > div {
  overflow: hidden;
}
article > div::after {
  --_height: 100px;

  content: "";
  position: absolute;
  bottom: calc(var(--_height) * -1);
  left: 0;
  width: 100%;
  height: var(--_height);
  background-image: url(//repo.bfw.wiki/bfwrepo/images/huajuan/scroll-bottom.png);
  background-repeat: no-repeat;
  background-position: center;
  background-size: var(--_width);
  z-index: 20;
  transition: 300ms ease-in-out;
}

/* scroll contents */
article > div > div {
  background-image: url(//repo.bfw.wiki/bfwrepo/images/huajuan/scroll-middle.png);
  background-repeat: no-repeat;
  background-size: var(--_width);
  width: var(--_width);
  padding: 0rem 8rem 4rem;
  height: 100%; /* to show the complete background image we ensure that the height is 100% */
}

/* 
The "in-viewport" class is added via JS using the IntersectionObserver 
NOTE - in some browsers this can now be done with CSS alone however the CSS method will not work on Firefox and some other older browsers
*/
section.in-viewport > article {
  grid-template-rows: 740px; /* reveal the content  - this is the full height of the chosen scroll middle section THE HEIGHT DEPENDS ON THE BACKGROUND IMAGE */
}
section.in-viewport > article > div:.........完整代码请登录后点击上方下载按钮下载查看

网友评论0