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

Change class depending on accordion / tabs mode #134

Closed ghost closed 6 years ago

ghost commented 7 years ago

Hello,

For better styling, I would like to add classes to the parent element depending on the mode of the tabs (tabs or accordion).

I saw that "activateState" callback function, but I don't know how to detect if we are in accordion or tab mode in order to give the correct class to my element.

Could you please point me the right direction ?

Thanks

Alex

coxrichuk commented 7 years ago

You need to bind the getState into a window resize:

var $tabs = $('.foo-tabs').responsiveTabs();
$(window).resize(function(){
     console.log($tabs.responsiveTabs('getState')); // returns tabs || accordion
});

It's a shame there isn't an event fired off when there is a change in state

EDIT

My bad there is an event

$tabs.on('tabs-activate-state', function(event, state){
    var old = state.oldState;
    var new = state.newState;
});
jellekralt commented 6 years ago

Thanks @coxrichuk