一页滚动网站 变形全屏导航

  • 源码大小:8.56KB
  • 所需积分:1积分
  • 源码编号:19JP-3479
  • 浏览次数:382次
  • 最后更新:2023年06月17日
  • 所属栏目:其他
我要下载
加入收藏
本站默认解压密码:19jp.com 或 19jp_com

简介

一个jQuery/CSS驱动的导航系统,它将汉堡按钮变形为全屏导航,其中包含从文档中的内容部分生成的锚链接。

非常适合单页滚动网站,在全屏页面部分之间切换时提供更好的导航体验。

如何使用它:

1.为必要的图标加载最新的Font Awesome Iconic Font。

<link rel="stylesheet" href="/path/to/font-awesome/all.min.css" />

2.为单页滚动网站创建一个板载屏幕。

<header>
  <div class="triangle left"><h1>This is a title</h1></div>
  <div class="triangle right"><h1>This is a title</h1></div>
  <button></button>
</header>

3.为全屏导航和页面部分创建HTML。

<nav>
  <ul>
    <li>Section 1</li>
    <li>Section 2</li>
    <li>Section 3</li>
  </ul>
  <div id="nav-close"><i class="fas fa-times"></i></div>
</nav>
<content>
  <section>Section 1</section>
  <section>Section 2</section>
  <section>Section 3</section>
</content>

4.必要的CSS样式。

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body {
  min-height: 300vh;
  background-image: linear-gradient(to top, #09203f 0%, #537895 100%);
}
header {
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
header h1, header button {
  position: relative;
  z-index: 10;
}
header h1 {
  text-transform: uppercase;
  letter-spacing: 1pt;
  font-size: 3em;
  color: #fff;
}
header button {
  font-family: "Font Awesome 5 Free";
  font-weight: 900;
  position: absolute;
  bottom: 100px;
  left: calc(50% - 60px);
  width: 120px;
  height: 50px;
  border: 0;
  box-shadow: 2px 1px 20px 0 rgba(0, 0, 0, 0.5);
  border-radius: 10px;
  cursor: pointer;
  background: #fff;
  font-size: 1em;
  color: #09203f;
  transition: all 0.8s cubic-bezier(0.645, 0.045, 0.355, 1), transform 0.3s cubic-bezier(0.455, 0.03, 0.515, 0.955), box-shadow 0.3s cubic-bezier(0.455, 0.03, 0.515, 0.955);
  overflow: hidden;
}
header button:hover {
  box-shadow: 0 0 0 0 rgba(0, 0, 0, 0.5);
}
header button:focus {
  outline: 0;
}
header button:before, header button:after {
  font-family: "Font Awesome 5 Free";
  transition: all 0.8s cubic-bezier(0.645, 0.045, 0.355, 1);
  top: 17px;
  position: absolute;
}
header button:before {
  content: "";
  opacity: 1;
  left: 53px;
}
header button:after {
  content: "";
  opacity: 0;
  left: 0;
}
header .triangle {
  position: absolute;
  z-index: 1;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(to top, #09203f 0%, #537895 100%);
  transition: all 0.8s cubic-bezier(0.645, 0.045, 0.355, 1);
  display: flex;
  justify-content: center;
  align-items: center;
  pointer-events: none;
}
header .triangle.left {
  clip-path: polygon(0 0, 0% 100%, 100% 100%);
}
header .triangle.right {
  clip-path: polygon(100% 0, 0 0, 100% 100%);
}
header.open .triangle.left {
  clip-path: polygon(0 0, 0 100%, 0 100%);
}
header.open .triangle.right {
  clip-path: polygon(100% 0, 100% 0, 100% 100%);
}
header.open button {
  left: 40px;
  bottom: 40px;
  width: 50px;
  border-radius: 50%;
}
header.open button:before {
  opacity: 0;
  left: 100%;
}
header.open button:after {
  opacity: 1;
  left: 18px;
}
header.open button.menu {
  width: 100%;
  height: 100%;
  bottom: 0;
  left: 0;
  border-radius: 0;
}
header.open button.menu:after {
  left: -100%;
}

content section {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 700;
  text-transform: uppercase;
  font-size: 1em;
  letter-spacing: 2pt;
  color: #fff;
}

nav {
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  display: none;
}
nav ul {
  list-style: none;
}
nav ul li {
  font-weight: 700;
  text-transform: uppercase;
  line-height: 2;
  letter-spacing: 1pt;
  font-size: 2em;
  color: #09203f;
  animation: fadeDown 0.5s forwards;
  opacity: 0;
  cursor: pointer;
  transform: translateY(-20px);
  transition: all 0.3s cubic-bezier(0.455, 0.03, 0.515, 0.955);
}
nav ul li:hover {
  text-shadow: 2px 1px 40px rgba(0, 0, 0, 0.5);
  opacity: 0.8;
}
nav ul li:nth-child(1) {
  animation-delay: 0.8s;
}
nav ul li:nth-child(2) {
  animation-delay: 0.9s;
}
nav ul li:nth-child(3) {
  animation-delay: 1s;
}
nav #nav-close {
  position: fixed;
  top: 40px;
  right: 40px;
  font-size: 1.5em;
  cursor: pointer;
  animation: fadeDown 0.5s forwards;
  animation-delay: 1.1s;
  opacity: 0;
  color: #09203f;
  transform: translateY(-20px);
}
@keyframes fadeDown {
  0% {
    opacity: 0;
    transform: translateY(-20px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

5.在</body>标签

<script src="/path/to/cdn/jquery.min.js"></script>

6.激活全屏导航。

// function to open/close nav
function toggleNav(){
  // if nav is open, close it
  if($("nav").is(":visible")){
    $("nav").fadeOut();
    $("button").removeClass("menu");
  }
  // if nav is closed, open it
  else{
    $("button").addClass("menu");
    $("nav").fadeIn().css('display', 'flex');
  }
}

// when clicking + button
$("button").click(function(){
  // when clicking ☰ button, open nav
  if($("header").hasClass("open")){
    toggleNav();
  }
  // when clicking + button, open header
  else{
    $("header").addClass("open");
  }
});

// close nav
$("#nav-close").click(function(){
  toggleNav();
});

// scroll to sections
$("nav li").click(function(){
  // get index of clicked li and select according section
  var index = $(this).index();
  var target = $("content section").eq(index);
  
  toggleNav();
  
  $('html,body').delay(300).animate({
    scrollTop: target.offset().top
  }, 500);
});

预览截图