jellekralt / Responsive-Tabs

Responsive Tabs is a jQuery plugin that provides responsive tab functionality. The tabs transform to an accordion when it reaches a CSS breakpoint. You can use this plugin as a solution for displaying tabs elegantly on desktop, tablet and mobile.
http://jellekralt.github.io/Responsive-Tabs/
MIT License
531 stars 228 forks source link

Scroll to top to active tab on acordeon state #79

Closed codev0 closed 8 years ago

codev0 commented 8 years ago

Hi. How can I do subj?

$('.vacancies__tabs').responsiveTabs({
            setHash: true,
            activate: function(event, tab) {
                if(window.innerWidth <= 768) {
                    var id = tab.selector;

                    var link = $(".r-tabs-accordion-title a[href$='"+ id +"'].r-tabs-anchor");

                    var position = 0;

                    position = link.offset().top - $('.header').outerHeight();

                    $('html, body').animate({
                        scrollTop: position + "px"
                    }, 500);

                    return false;
                }
            }
        });

This code is work, but event work on page load. How to add this statement to to click event? Or exclude page load?

codev0 commented 8 years ago

Fixed. But I think add custom function on click event will be useful.

$('.vacancies__tabs').responsiveTabs({
            setHash: true
        });

        if (window.innerWidth <= 768) {
            $('.vacancies__tabs').on('tabs-activate', function(event, tab) {
                event.preventDefault();
                var id = tab.selector;
                var link = $(".r-tabs-accordion-title a[href$='" + id + "'].r-tabs-anchor");

                var position = 0;
                position = link.offset().top - $('.header').outerHeight();

                $('html, body').animate({
                    scrollTop: position + "px"
                }, 500);
            });
        }
evoactivity commented 8 years ago

Don't think this should have been closed, having this as part of the core plugin would make sense. If there is a lot of content in one tab (activate tab) and not a lot in the next, scrolling down then clicking the next accordion title essentially hides the content from the user making them scroll back up.