Scrollify.js 在当前部分添加 class
Scrollify.js add class on current section
我正在尝试使用 scrollify.js 在页面的当前部分添加 'active' class 之类的内容。
可以获取索引值,但不能获取部分 ID 或部分 class!如何获取当前部分的 ID 或 class.
这是我尝试实现的示例代码。
<section id="first" data-section="first" class="scroll-section"> </section>
before:function(index, sections) {
alert(index);
},
这个return索引值。我正在尝试获取部分 ID first.
提前致谢。
<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>
分类 $.scrollify.current()
它 returns 当前部分。
我正在尝试使用 scrollify.js 在页面的当前部分添加 'active' class 之类的内容。
可以获取索引值,但不能获取部分 ID 或部分 class!如何获取当前部分的 ID 或 class.
这是我尝试实现的示例代码。
<section id="first" data-section="first" class="scroll-section"> </section>
before:function(index, sections) {
alert(index);
},
这个return索引值。我正在尝试获取部分 ID first.
提前致谢。
<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>
分类 $.scrollify.current()
它 returns 当前部分。