我正在尝试使用scrollify.js 将诸如“事件”类之类的内容添加到页面中的当前部分。
我能够获取索引值,但无法获取节 ID 或节类!如何获取当前部分的 id 或类。
这是我尝试实现的示例代码。
<section id="first" data-section="first" class="scroll-section"> </section>
before:function(index, sections) {
alert(index);
},
此返回索引值。我正在尝试首先获取部分 ID。
提前致谢。
最佳答案
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="jquery.scrollify.js"></script>
<style>
.sectioncolor {
background-color: black;
}
</style>
<script>
$(function() {
$.scrollify({
section : ".section-class-name",
sectionName : "section-name",
before:function(index, sections) {
var sno = index+1;
$(".section-class-name").removeClass("sectioncolor");
$(".section-class-name:nth-child("+sno+")").addClass("sectioncolor");
},
after:function(index, sections) {
var sno = index+1;
$(".section-class-name").removeClass("sectioncolor");
$(".section-class-name:nth-child("+sno+")").addClass("sectioncolor");
},
});
});
</script>
</head>
<body>
<div class="section-class-name" data-section-name="home" style="height:500px;border:1px solid red;"></div>
<div class="section-class-name" data-section-name="about" style="height:500px;border:1px solid black;"></div>
</body>
</html>
关于javascript - Scrollify.js 在当前部分添加类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45372081/