jQuery串行滚动: Add class to active item

标签 jquery html css scrollto serialscroll

我正在使用 Ariel Flesler 的serialScroll 脚本,并且想向事件或突出显示的元素添加一个类,以便我可以使用 CSS 对其进行样式设置。正在阅读the documentation我发现了通知触发器,但我不确定如何/是否可以使用它来完成此任务。

这是我的代码:

jQuery

jQuery(function( $ ){

    $('#slideshow').serialScroll({
        items:'li',
        prev:'#screen2 a.prev',
        next:'#screen2 a.next',
        offset:-180,
        start: 0,
        duration:1200,
        force:true,
        stop:true,
        lock:false,
        cycle:false,
        jump: true
    });

});

HTML

    <div id="screen2">
    <div id="buttons">
        <a class="prev" href="#">Previous</a>
        <a class="next" href="#">Next</a>
        <br class="clear" />
    </div>
    <div id="slideshow">
        <ul>
            <li><img src="http://www.stockvault.net/data/s/113497.jpg" /></li>
            <li><img src="http://www.stockvault.net/data/s/100177.jpg" /></li>
            <li><img src="http://www.stockvault.net/data/s/101916.jpg" /></li>
            <li><img src="http://www.dreamstime.com/animal-steps-in-snow-thumb12853223.jpg" /></li>
            <li><img src="http://www.dreamstime.com/animal-eggs-thumb15876342.jpg" /></li>
            <li><img src="http://www.dreamstime.com/animal-cat-thumb15385101.jpg" /></li>
            <li><img src="http://www.dreamstime.com/green-nature-thumb596309.jpg" /></li>
            <li><img src="http://www.dreamstime.com/office-in-nature-thumb3256171.jpg" /></li>
            <li><img src="http://www.dreamstime.com/nature-tree-thumb16030502.jpg" /></li>
            <li><img src="http://www.dreamstime.com/gift-of-the-nature-thumb15977958.jpg" /></li>
            <li><img src="http://www.dreamstime.com/nature-abstract-thumb3615419.jpg" /></li>
            <li><img src="http://www.dreamstime.com/nature-path-in-forest-with-sunshine-thumb8241130.jpg" /></li>
            <li><img src="http://www.dreamstime.com/nature-walk-thumb8436665.jpg" /></li>
            <li><img src="http://www.dreamstime.com/save-the-nature-thumb15696583.jpg" /></li>
        </ul>
    </div>
</div>

我是否误解了通知触发器的功能?如果是这样,是否有其他方法可以实现我所追求的目标?

最佳答案

在插件示例页面中,以下是 onBefore 的使用方式:

onBefore:function( e, elem, $pane, $items, pos ){
    /**
    * 'this' is the triggered element 
    * e is the event object
    * elem is the element we'll be scrolling to
    * $pane is the element being scrolled
    * $items is the items collection at this moment
    * pos is the position of elem in the collection
    * if it returns false, the event will be ignored
    */
    //those arguments with a $ are jqueryfied, elem isn't.
}

在该函数中,您可以添加事件类,并使用 onAfter 函数从前一个元素中删除该类。

关于jQuery串行滚动: Add class to active item,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8345770/

相关文章:

jquery - 可以使用 xhrFields 将 onprogress 功能添加到 jQuery.ajax() 中吗?

javascript - 一旦尝试就清除样式

jquery - 检测到水平 div 的末尾,并停止

javascript - Jquery Datatable 将一个表中的一行添加到另一个表中

html - 位置绝对 div 宽度与父级不匹配

javascript - 使背景图像在 CSS 网格中可点击

css - 下拉菜单下的间隙

javascript - 拆分导航溢出 - 如果浏览器窗口宽度较小,则将页眉拆分为页脚

php - 带有滚动条的动画文本

html - 当图像位于顶部时,纯 CSS 菜单不起作用