我在我的functions.js中得到了这个
$('.cta').click(function(){
var curActive = $('.side-nav').find('.is-active'),
curPos = $('.side-nav').children().index(curActive),
lastItem = $('.side-nav').children().length - 1,
nextPos = lastItem;
updateNavs(lastItem);
updateContent(curPos, nextPos, lastItem);
});
如何使用.cta类滚动到下一个或上一个元素/项目,而不是最后一个。是否可以将其设置为使用div ID?
我正在玩这个主题: Global
谢谢
答案 0 :(得分:0)
您在这里:
$('.cta').click(function() {
let __nav = $('.side-nav'),
__current = __nav.find('.is-active'),
want_next = $(this).hasClass('next'),
current_active = __nav.children().index(__current),
next_active = (want_next) ? current_active + 1 : current_active - 1;
next_active = (next_active > __nav.children().length) ? __nav.children().length : ((next_active < 0) ? 0 : next_active);
__current.removeClass('is-active');
$(__nav.children()[next_active]).addClass('is-active');
});