jQuery localScroll-如何将类添加到单击的< a>中? [英] jQuery localScroll - how to add class to clicked <a>?

查看:63
本文介绍了jQuery localScroll-如何将类添加到单击的< a>中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在导航中通过href来控制滚动内容.我使用localScroll滚动内容.因此问题是如何向内容的当前显示部分的属性添加类.这就是我启动滚动的方式

I got a scrolling content controlled via href's in navigation. I use localScroll to scroll the content. So question is how to add class to attribute of currently displayedpart of a content. That's how I initiate scroll

<script style="text/javascript">
        $(document).ready(function () {
        $('.navigation').localScroll();
        });
    </script>

谢谢, 槟榔

推荐答案

我知道了:

<script style="text/javascript">
        $(document).ready(function () {
            $('.navigation').localScroll();
            $('.navigation').find('a').click(selectNav);
            function selectNav() {
              $(this)
                .parents('ul:first') 
                  .find('a') 
                    .removeClass('selected') 
                  .end() 
                .end()
                .addClass('selected');
                }
                function trigger(data) {
                  var el = $('.navigation').find('a[href$="' + data.id + '"]').get(0);
                  selectNav.call(el);
                    }
        });
    </script>

这篇关于jQuery localScroll-如何将类添加到单击的&lt; a&gt;中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆