javascript - 在特定点而不是像素处滚动添加删除类
问题描述
我需要在页面上的特定点删除和添加一个类,但该点在每个页面上都不同,因此“if (scroll >= 300)”不适用于所有页面。有没有办法基于滚动到部分 id 来做到这一点?
$(function() {
//caches a jQuery object containing the content element
var content = $(".isi-fixed");
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll >= 300) {
content.removeClass('isi-fixed').addClass("isi");
} else {
content.removeClass("isi").addClass('isi-fixed');
}
});
我的CSS是
.isi-fixed {
width: 100%;
height: 20%;
bottom: 0px;
right: 0px;
padding: 50px;
opacity: 0.5;
overflow-y: scroll;
visibility: visible;
display: block;
z-index: 500 !important;
position: fixed;
background-color: #E7E7E7;
}
和
.isi {
width: 100%;
padding: 50px;
visibility: visible;
position: relative;
background-color: #E7E7E7;
}
解决方案
推荐阅读
- javascript - Mongoose:如何发布到 Schema 内的数组中
- r - 如何在R中的数据框中获取列表的最大值
- android - 空对象上的 FrameLayout.getId()
- python - 返回.png 来自 Jenkins 构建的文件
- cmake - 使用没有相对路径的 CMake 创建 Zip
- python - 如何访问 RecycleView Kivy 的元素?
- node.js - 使用 Discord.js 在 .json 文件中搜索商品并显示其价格
- reactjs - 获取所有数据后React js刷新功能组件
- heroku - 使用 Fixie(或其他)通过 Heroku 中的静态 IP 发出请求?
- kubernetes - 有没有办法在 kubernetes 的环境变量上使用方括号?