jquery 2点击开火

时间:2017-11-01 17:10:32

标签: jquery events

我真的很难找到为什么我的jquery导航在页面首次加载时会点击2次点击。一旦您开始浏览网站,它就很好了。它就在第一次加载时。下面是jquery和html nav。

我还有一个固定的页眉,所以有一个79px的边距

<script>
jQuery(document).ready(function ($) {
    $(window).scroll(function () {
        var cccvvv = $(window).height() + 500;
        if ($(window).scrollTop() + cccvvv > $(document).height()) {
            $('.js-next').css('display', 'none');
        } else {
            $('.js-next').css('display', 'block');
        }
    });
    $('.js-next').click(function (e) {
        var selected = $(".js-list-item.js-current-panel");
        var anchors = $(".js-list-item");
        var pos = anchors.index(selected);
        var next = anchors.get(pos + 1);
        var prev = anchors.get(pos - 1);
        target = $(next);
        $(selected).removeClass("js-current-panel");
        $(next).addClass("js-current-panel");
        if (target.offset()) {
            $('html, body').animate({scrollTop: target.offset().top - '79'}, 600);
        }
        e.preventDefault();
    });
    $('.js-prev').click(function (e) {
        var selected = $(".js-list-item.js-current-panel");
        var anchors = $(".js-list-item");
        var pos = anchors.index(selected);
        var next = anchors.get(pos + 1);
        var prev = anchors.get(pos - 1);
        target = $(prev);
        $(selected).removeClass("js-current-panel");
        $(prev).addClass("js-current-panel");
        if (target.offset()) {
            $('html, body').animate({scrollTop: target.offset().top - '79'}, 600);
        }
        e.preventDefault();
    });
});
</script>

<div class="nav">
<div class="container">
<a class="link js-prev js-scroll-to" href="#"><img src="/wp-content/uploads/2013/07/up.png" alt=""></a>
<a class="link js-next" href="javascript:void(0)"><img src="/wp-content/uploads/2013/07/down.png" alt=""></a>
</div>
</div>

0 个答案:

没有答案