0

I got this in my 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);

});

How can I use .cta class to scroll to next or previous element/item instead of last. Is it possible to also set it to use div id?

I'm playing with this theme: Global

thanks

1 Answer 1

0

Here you go:

$('.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');

});

Working example here

2
  • Thanks, but that is not working for me. I'm trying to use .cta class on button or link to trigger a new page Aug 2, 2018 at 9:38
  • @WwelsonDdolb And what's not working? You just have to add the next class into the class list of the mentioned link / button, that's all.
    – CodiMech25
    Aug 2, 2018 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.