javascript - 如何在 Fullpage.js 上滚动时更改类的背景颜色?
问题描述
我有一个带有 .header 类的 div,我希望它的背景颜色在滚动时变为透明。我怎么能在javascript上做到这一点?我使用 fullpage.js 插件,顺便说一句,只有 2 个部分。
<body>
<div class="header">
CONTENTS HERE
</div>
<div id="fullPage">
<div class="section bg">
CONTENTS HERE
</div>
<div class="section aboutme">
CONTENTS HERE
</div>
</div>
</body>
.header {
background-color: rgba(0, 0, 0, 0.2);
text-align: center;
padding: 8px 15px;
overflow: hidden;
min-height: 46px;
position: absolute;
width: 100%;
top: 0;
z-index: 999;
解决方案
您可以使用fullpage.js 状态类或回调来完成它。
这是使用整页状态类的示例: https ://codepen.io/alvarotrigo/pen/VwbxbYR
.fp-viewing-1-0 button{
background: blue;
}
fp-viewing-1-0
基本上意味着 fullpage.js 在第二部分和第一张幻灯片上。因此,部分和幻灯片都使用基于 0 的索引。
这是另一个使用回调的示例: https ://codepen.io/alvarotrigo/pen/XbPNQv
fullpage.js 文档中的更多示例
afterLoad: function(origin, destination, direction){
var loadedSection = this;
//using index
if(origin.index == 2){
alert("Section 3 ended loading");
}
//using anchorLink
if(origin.anchor == 'secondSlide'){
alert("Section 2 ended loading");
}
}
推荐阅读
- excel-2010 - 如果单元格中有日期,则返回日期;如果单元格为空白或有文本,则返回 N/A 或空白
- jquery - JQuery Flip取消功能
- sql-server - SSRS 2016 偶发错误 rrRenderingError
- javascript - 如何防止在 Kendo Sortable / Integration - ListView 中对项目进行排序(固定位置)?
- php - Symfony 4:使用 manyToOne 加入的学说迁移
- sql - 添加休眠更新时为什么会出现排序规则冲突?
- nrf52 - nrf52840 加密狗的初学者设置
- r - 从 R 中的高数据或宽数据计算均值
- c# - 实体框架结构
- doctrine-orm - 编译器通过 - 解析目标实体不加载