Simple Tabs on Desktop, Accordion on Mobile (vanilla JS)

Simple Tabs on Desktop, Accordion on Mobile (vanilla JS)

Most of the time we face this requirment that we need tabs on desktop and same component we have to convert accoridans for the mobile users , so instead of implimenting two different component for mobile and desktop where we hide the desktop component in mobile and mobile component in desktop , we will create a single component and through javascript we will convert that in to tabs in desktop and accordian in mobiles, Please check the demo video first .

The code is very simple and customizable by the developer and it also has some setting to change the view in mobile and tablet , please go through the below installation so you will bw able use this plugin

Implementing the HTML

The HTML is straightforward to implement we have a main container with data attribute data-acc-tab-type whose container value is either tabs or accordion, so if a user wants to create accordion an then the accordion value needs to be passed to that data attribute or if tab structure is required then the tab is passed in the attribute, so for tab it should be data-acc-tab-type=”tabs” and for accordion, we need to pass it as data-acc-tab-type=”accordion” and as a children element we have <div class=”ss_acc_tab_section active gtm-style-59″ data-tabId=”tab_one”> where data-tabId is the unique value we need to pass then we have <div class=”ss_acc_tab_heading”> which contains the tab text, so the final HTML code is as below

Implimenting javascript

We have a customizable and easy javascript in which we only need to pass setting according to our requirement is we need tab in desktop and accordion in mobile version then we only need to pass mobileTabAccordian: true

please follow the below javascript code and implement in you project 

Implimenting CSS

Css is very simple to impliment accordind to you desing requirments , bt make sure of active classes wich will display and hide the accordians on click

Demo Live

Tab One

Why do we use it tab one?

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using ‘Content here, content here’, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for ‘lorem ipsum’ will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).

Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of “de Finibus Bonorum et Malorum” (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, “Lorem ipsum dolor sit amet..”, comes from a line in section 1.10.32.

Tab Two

Why do we use it tab two?

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Tab Three

Why do we use it tab three?

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of “de Finibus Bonorum et Malorum” (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, “Lorem ipsum dolor sit amet..”, comes from a line in section 1.10.32.

Download File

Further reading