0

我正在尝试使用 scrollify.js 在页面的当前部分中添加类似“活动”类的内容。

能够获取索引值,但不能获取部分 ID 或部分类!如何获取当前部分的 id 或类。

这是我试图实现的示例代码。

<section id="first" data-section="first" class="scroll-section"> </section>

before:function(index, sections) {
    alert(index);
},

此返回索引值。我正在尝试首先获取部分id

提前致谢。

4

2 回答 2

2
  <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>
于 2017-07-28T12:37:49.773 回答
1

调用$.scrollify.current()它返回当前部分。

于 2017-07-29T11:52:46.837 回答