我是靠谱客的博主 平淡溪流,这篇文章主要介绍滚动渐变导航栏滚动渐变导航栏,现在分享给大家,希望可以做个参考。

滚动渐变导航栏

教程地址:原文地址(YouTube)

B站教程:原文转载(bilibili)

两个视频的内容相同,第二个为转载

效果图

在这里插入图片描述

代码区

html

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<header> <!-- logo --> <a href="#" class="logo">Logo</a> <!-- 导航栏 --> <ul> <li><a href="#">Home</a></li> <li><a href="#">Aboout</a></li> <li><a href="#">Services</a></li> <li><a href="#">Portfolio</a></li> <li><a href="#">Team</a></li> <li><a href="#">Contact</a></li> </ul> </header> <!-- 内容 --> <section class="banner"></section>

CSS

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
* { margin: 0; /* 外边距 */ padding: 0; /* 内边距 */ box-sizing: border-box; /* 盒子大小规则 */ font-family: sans-serif; /* 字体样式 */ } body { background: #000; /* 背景颜色 */ min-height: 200vh; /* 最小高度 */ } header { position: fixed; /* 根据浏览器进行定位 */ top: 0; left: 0; width: 100%; /* 宽 */ display: flex; /* 弹性盒模型 */ justify-content: space-between; /* 主轴对齐方式 */ align-items: center; /* 交叉轴对齐方式 */ transition: 0.6s; /* 过渡时间 */ padding: 40px 100px; z-index: 1000; /* 层叠顺序 */ } header .logo { position: relative; font-weight: 700; color: #fff; text-decoration: none; /* 文字装饰 */ font-size: 2em; /* 字体大小 */ text-transform: uppercase; /* 字体大写 */ letter-spacing: 2px; /* 字符间距 */ transition: 0.6s; } header ul { position: relative; display: flex; justify-content: center; align-items: center; } header ul li { position: relative; list-style: none; } header ul li a { position: relative; margin: 0 15px; text-decoration: none; color: #fff; letter-spacing: 2px; font-weight: 500px; transition: 0.6s; } .banner { position: relative; width: 100%; height: 100vh; background: url(../img/bg.jpg); background-size: cover; /* 背景大小:裁切 */ } /* 修改后 */ header.sticky .logo, header.sticky ul li a { color: #000; } header.sticky { padding: 5px 100px; background: #fff; }

JS

复制代码
1
2
3
4
5
6
7
8
// 添加滚动事件 window.addEventListener('scroll', function() { //获取元素 var header = document.querySelector("header"); // 添加类 header.classList.toggle("sticky", window.scrollY > 0 ) });

教程地址:原文地址(YouTube)

B站教程:原文转载(bilibili)

最后

以上就是平淡溪流最近收集整理的关于滚动渐变导航栏滚动渐变导航栏的全部内容,更多相关滚动渐变导航栏滚动渐变导航栏内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(73)

评论列表共有 0 条评论

立即
投稿
返回
顶部