├── .github └── FUNDING.yml ├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── dist ├── scrollable-tabs.css ├── scrollable-tabs.js ├── scrollable-tabs.min.css └── scrollable-tabs.min.js ├── example ├── index.html └── index_b4.html ├── package-lock.json ├── package.json ├── preview.gif └── src ├── css ├── scrollable-tabs.css └── scrollable-tabs.min.css └── js ├── scrollable-tabs.js └── scrollable-tabs.min.js /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [fanmixco] 4 | custom: ['https://www.buymeacoffee.com/fanmixco'] 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .github/ 2 | src/ 3 | preview.gif 4 | README.md 5 | example/index_b4.html 6 | .gitignore 7 | node_modules/ 8 | dist/scrollable-tabs.css 9 | dist/scrollable-tabs.js -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Scrollable Tabs for Bootstrap 5 2 | 3 | A simple plugin to create scrollable tabs with Bootstrap 5. 4 | 5 | [![preview][1]][1] 6 | 7 | ## Support me: 8 | 9 | [![sponsor me][2]](https://www.buymeacoffee.com/fanmixco) 10 | 11 | ## Usage: 12 | 13 | ## Breaking change from 1.1.0+: 14 | 15 | To allow more than one set of tabs, it required to add a new class to wrap the tabs `tab-wrapper`. It must be added to use it. 16 | 17 | ### Install: 18 | 19 | - [Download the latest release](https://github.com/SupernovaIC/scrollable-tabs-bootstrap-5/archive/refs/tags/v1.1.0.zip) 20 | 21 | - Install with [npm](https://www.npmjs.com/): `npm i scrolling-tabs-bootstrap-5` 22 | 23 | |Latest Release|Downloads| 24 | |:------------:|:------------:| 25 | |[![npm version](https://img.shields.io/npm/v/scrolling-tabs-bootstrap-5)](https://www.npmjs.com/package/scrolling-tabs-bootstrap-5)|[![NuGet Badge SpotsDialog.Xamarin](https://img.shields.io/npm/dt/scrolling-tabs-bootstrap-5)](https://www.npmjs.com/package/scrolling-tabs-bootstrap-5/)| 26 | 27 | ### Required libraries: 28 | 29 | ```html 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | ``` 41 | 42 | ### HTML example: 43 | 44 | ```html 45 |
46 |
47 |
48 |
49 | 57 |
58 |
59 |
60 | This is the content of Tab 1... 61 |
62 |
63 | This is the content of Tab 2... 64 |
65 |
66 | This is the content of Tab 3... 67 |
68 |
69 | This is the content of Tab 4... 70 |
71 |
72 | This is the content of Tab 5... 73 |
74 |
75 | This is the content of Tab 6... 76 |
77 |
78 |
79 | ``` 80 | 81 | **Based on:** 82 | 83 | https://www.codeply.com/go/Loo3CqsA7T 84 | 85 | [1]: preview.gif 86 | [2]: https://raw.githubusercontent.com/FANMixco/Xamarin-SearchBar/master/bmc-rezr5vpd.gif 87 | 88 | 89 | ## Follow me on 90 | 91 | | LinkedIn |YouTube|Amazon|Goodreads|Instagram|Cyber Prophets|Sharing Your Stories|TikTok| 92 | |:----------|:------------:|:------------:|:------------:|:------------:|:------------:|:------------:|:------------:| 93 | |[![LinkedIn](https://i.sstatic.net/idQWu.png)](https://www.linkedin.com/in/federiconavarrete)|[![YouTube](https://i.sstatic.net/CFPMR.png)](https://youtube.com/@FedericoNavarrete)|[![Amazon](https://i.sstatic.net/NFOeE.png)](https://www.amazon.com/Federico-Navarrete/e/B08NJTXQRV)|[![Goodreads](https://i.sstatic.net/oBk0g.jpg)](https://www.goodreads.com/author/show/21125413.Federico_Navarrete)|[![Instagram](https://i.sstatic.net/PIfqY.png)](https://www.instagram.com/federico_the_consultant)|[![RedCircle Podcast](https://i.sstatic.net/4XICF.png)](https://redcircle.com/shows/cyber-prophets)|[![RedCircle Podcast](https://i.sstatic.net/4XICF.png)](https://redcircle.com/shows/sharing-your-stories)|[![TikTok](https://i.sstatic.net/pP7X2.png)](https://www.tiktok.com/@federicostories)| 94 | -------------------------------------------------------------------------------- /dist/scrollable-tabs.css: -------------------------------------------------------------------------------- 1 | 2 | .wrapper-nav { 3 | position:relative; 4 | margin:0 auto; 5 | overflow:hidden; 6 | padding:5px; 7 | height:50px; 8 | } 9 | 10 | .list { 11 | position:absolute; 12 | left:0px; 13 | top:0px; 14 | min-width:3500px; 15 | margin-top:0px; 16 | } 17 | 18 | .list li{ 19 | display:table-cell; 20 | position:relative; 21 | text-align:center; 22 | cursor:grab; 23 | cursor:-webkit-grab; 24 | color:#efefef; 25 | vertical-align:middle; 26 | } 27 | 28 | .scroller { 29 | text-align:center; 30 | cursor:pointer; 31 | display:none; 32 | padding:7px; 33 | white-space:no-wrap; 34 | vertical-align:middle; 35 | background-color:#fff; 36 | } 37 | 38 | .pointer {cursor: pointer;} 39 | -------------------------------------------------------------------------------- /dist/scrollable-tabs.js: -------------------------------------------------------------------------------- 1 | //let move = require('move'); 2 | // Function to initialize scrollable tabs for a specific wrapper 3 | function initializeScrollableTabs(wrapper) { 4 | const scrollBarWidths = 40; 5 | const scrollerRight = wrapper.querySelector(".scroller-right"); 6 | const scrollerLeft = wrapper.querySelector(".scroller-left"); 7 | const list = wrapper.querySelector(".list"); 8 | const lastNavLink = list.querySelectorAll(".nav-item.nav-link")[list.querySelectorAll(".nav-item.nav-link").length - 1]; 9 | let btnTriggered = false; 10 | 11 | let widthOfList = function () { 12 | let itemsWidth = 0; 13 | const listLinks = list.querySelectorAll("a"); 14 | 15 | listLinks.forEach((el) => { 16 | let itemWidth = getOuterWidth(el); 17 | itemsWidth += itemWidth; 18 | }); 19 | 20 | return itemsWidth; 21 | }; 22 | 23 | let widthOfHidden = function (w) { 24 | w = (!w) ? 0 : w; 25 | const oW = getOuterWidth(wrapper.querySelector(".wrapper-nav")) - w; 26 | const ww = parseFloat((0 - oW).toFixed(3)); 27 | const hw = (oW - widthOfList() - getLeftPosi()) - scrollBarWidths; 28 | const rp = document.body.clientWidth - (getOuterLeft(lastNavLink) + getOuterWidth(lastNavLink)) - w; 29 | 30 | if (ww > hw) { 31 | return (rp > ww ? rp : ww); 32 | } else { 33 | return (rp > hw ? rp : hw); 34 | } 35 | }; 36 | 37 | let getLeftPosi = () => { 38 | const lp = getOuterLeft(list); 39 | const wrapperLeft = getOuterLeft(wrapper.querySelector(".wrapper-nav")); 40 | 41 | return lp - wrapperLeft; 42 | }; 43 | 44 | let reAdjust = () => { 45 | let rp = document.body.clientWidth - (getOuterLeft(lastNavLink) + getOuterWidth(lastNavLink)); 46 | 47 | if (getOuterWidth(wrapper.querySelector(".wrapper-nav")) < widthOfList() && (rp < 0)) { 48 | scrollerRight.style.display = 'flex'; 49 | unfade(scrollerRight); 50 | } else { 51 | scrollerRight.style.display = 'none'; 52 | } 53 | 54 | if (getLeftPosi() < 0) { 55 | scrollerLeft.style.display = 'flex'; 56 | unfade(scrollerLeft); 57 | } else { 58 | scrollerLeft.style.display = 'none'; 59 | } 60 | 61 | btnTriggered = false; 62 | }; 63 | 64 | scrollerRight.addEventListener("click", () => { 65 | if (btnTriggered) return; 66 | 67 | btnTriggered = true; 68 | 69 | fade(scrollerLeft); 70 | unfade(scrollerRight); 71 | 72 | let wR = getOuterWidth(scrollerRight); 73 | 74 | move(list).add("left", +widthOfHidden(wR), 200).end().then(() => { 75 | reAdjust(); 76 | }); 77 | }); 78 | 79 | scrollerLeft.addEventListener("click", () => { 80 | if (btnTriggered) return; 81 | 82 | btnTriggered = true; 83 | 84 | fade(scrollerRight); 85 | unfade(scrollerLeft); 86 | 87 | let wL = getOuterWidth(scrollerLeft); 88 | 89 | move(list).add("left", -getLeftPosi() + wL, 200).end().then(() => { 90 | reAdjust(); 91 | }); 92 | }); 93 | 94 | window.addEventListener('resize', () => { 95 | reAdjust(); 96 | }, true); 97 | 98 | reAdjust(); 99 | } 100 | 101 | let getOuterLeft = (elem) => elem.getBoundingClientRect().left; 102 | 103 | let getOuterWidth = (elem) => parseFloat(window.getComputedStyle(elem).width); 104 | 105 | function fade(elem) { 106 | elem.style.display = "none"; 107 | elem.style.transition = "opacity 0.6s"; 108 | elem.style.opacity = 0; 109 | } 110 | 111 | function unfade(elem) { 112 | elem.style.display = "block"; 113 | elem.style.transition = "opacity 0.6s"; 114 | elem.style.opacity = 1; 115 | } 116 | 117 | // Initialize scrollable tabs for each tab set 118 | document.querySelectorAll('.tab-wrapper').forEach(wrapper => { 119 | initializeScrollableTabs(wrapper); 120 | }); -------------------------------------------------------------------------------- /dist/scrollable-tabs.min.css: -------------------------------------------------------------------------------- 1 | .wrapper-nav{position:relative;margin:0 auto;overflow:hidden;padding:5px;height:50px}.list{position:absolute;left:0;top:0;min-width:3500px;margin-top:0}.list li{display:table-cell;position:relative;text-align:center;cursor:grab;cursor:-webkit-grab;color:#efefef;vertical-align:middle}.scroller{text-align:center;cursor:pointer;display:none;padding:7px;white-space:no-wrap;vertical-align:middle;background-color:#fff}.pointer{cursor:pointer} -------------------------------------------------------------------------------- /dist/scrollable-tabs.min.js: -------------------------------------------------------------------------------- 1 | function initializeScrollableTabs(e){const t=e.querySelector(".scroller-right"),l=e.querySelector(".scroller-left"),r=e.querySelector(".list"),n=r.querySelectorAll(".nav-item.nav-link")[r.querySelectorAll(".nav-item.nav-link").length-1];let i=!1,a=function(){let e=0;return r.querySelectorAll("a").forEach((t=>{let l=getOuterWidth(t);e+=l})),e},d=()=>getOuterLeft(r)-getOuterLeft(e.querySelector(".wrapper-nav")),o=()=>{let r=document.body.clientWidth-(getOuterLeft(n)+getOuterWidth(n));getOuterWidth(e.querySelector(".wrapper-nav")){if(i)return;i=!0,fade(l),unfade(t);let u=getOuterWidth(t);move(r).add("left",+function(t){t=t||0;const l=getOuterWidth(e.querySelector(".wrapper-nav"))-t,r=parseFloat((0-l).toFixed(3)),i=l-a()-d()-40,o=document.body.clientWidth-(getOuterLeft(n)+getOuterWidth(n))-t;return r>i?o>r?o:r:o>i?o:i}(u),200).end().then((()=>{o()}))})),l.addEventListener("click",(()=>{if(i)return;i=!0,fade(t),unfade(l);let e=getOuterWidth(l);move(r).add("left",-d()+e,200).end().then((()=>{o()}))})),window.addEventListener("resize",(()=>{o()}),!0),o()}let getOuterLeft=e=>e.getBoundingClientRect().left,getOuterWidth=e=>parseFloat(window.getComputedStyle(e).width);function fade(e){e.style.display="none",e.style.transition="opacity 0.6s",e.style.opacity=0}function unfade(e){e.style.display="block",e.style.transition="opacity 0.6s",e.style.opacity=1}document.querySelectorAll(".tab-wrapper").forEach((e=>{initializeScrollableTabs(e)})); -------------------------------------------------------------------------------- /example/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Scrollable Tabs Bootstrap 5 11 | 13 | 16 | 17 | 18 | 19 | 20 | 21 |
22 |
23 |
24 |
25 | 44 |
45 |
46 |
47 | This is the content of Tab 1... 48 |
49 |
50 | This is the content of Tab 2... 51 |
52 |
53 | This is the content of Tab 3... 54 |
55 |
56 | This is the content of Tab 4... 57 |
58 |
59 | This is the content of Tab 5... 60 |
61 |
62 | This is the content of Tab 6... 63 |
64 |
65 | This is the content of Tab 7... 66 |
67 |
68 | This is the content of Tab 8... 69 |
70 |
71 | This is the content of Tab 9... 72 |
73 |
74 | This is the content of Tab 10... 75 |
76 |
77 | This is the content of Tab 11... 78 |
79 |
80 | This is the content of Tab 12... 81 |
82 |
83 | This is the content of Tab 13... 84 |
85 |
86 | This is the content of Tab 14... 87 |
88 |
89 | This is the content of Tab 15... 90 |
91 |
92 | This is the content of Tab 16... 93 |
94 | 95 |
96 |
97 | 98 |
99 |
100 |
101 |
102 | 114 |
115 |
116 |
117 | This is the content of Tab 17... 118 |
119 |
120 | This is the content of Tab 18... 121 |
122 |
123 | This is the content of Tab 19... 124 |
125 |
126 | This is the content of Tab 20... 127 |
128 |
129 | This is the content of Tab 21... 130 |
131 |
132 | This is the content of Tab 22... 133 |
134 |
135 | This is the content of Tab 23... 136 |
137 |
138 | This is the content of Tab 24... 139 |
140 |
141 | This is the content of Tab 25... 142 |
143 |
144 |
145 | 146 | 147 | 148 | 149 | 150 | 151 | -------------------------------------------------------------------------------- /example/index_b4.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Scrollable Tabs Bootstrap 4 7 | 8 | 9 | 10 | 11 | 12 | 13 | 51 | 52 | 53 |
54 |
55 |
56 |
57 | 75 |
76 |
77 |
78 | This is the content of Tab 1... 79 |
80 | 83 | 86 | 89 | 92 | 95 | 98 | 101 | 104 | 107 | 110 | 113 | 116 | 119 | 122 | 125 | 126 |
127 |
128 | 129 | 216 | 217 | 218 | 219 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "scrolling-tabs-bootstrap-5", 3 | "version": "1.0.10", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "scrolling-tabs-bootstrap-5", 9 | "version": "1.0.10", 10 | "license": "Apache 2.0", 11 | "dependencies": { 12 | "bootstrap": "^5.1.3", 13 | "bootstrap-icons": "^1.7.2", 14 | "move-js": "^0.5.0" 15 | } 16 | }, 17 | "node_modules/@popperjs/core": { 18 | "version": "2.11.2", 19 | "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.2.tgz", 20 | "integrity": "sha512-92FRmppjjqz29VMJ2dn+xdyXZBrMlE42AV6Kq6BwjWV7CNUW1hs2FtxSNLQE+gJhaZ6AAmYuO9y8dshhcBl7vA==", 21 | "peer": true, 22 | "funding": { 23 | "type": "opencollective", 24 | "url": "https://opencollective.com/popperjs" 25 | } 26 | }, 27 | "node_modules/after-transition": { 28 | "version": "0.0.4", 29 | "resolved": "https://registry.npmjs.org/after-transition/-/after-transition-0.0.4.tgz", 30 | "integrity": "sha1-FlNWBQeJPYIOUDI927qu/SrhdVU=", 31 | "dependencies": { 32 | "css-emitter-component": "~0.1.1", 33 | "has-transitions": "~0.3.0" 34 | } 35 | }, 36 | "node_modules/bootstrap": { 37 | "version": "5.1.3", 38 | "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-5.1.3.tgz", 39 | "integrity": "sha512-fcQztozJ8jToQWXxVuEyXWW+dSo8AiXWKwiSSrKWsRB/Qt+Ewwza+JWoLKiTuQLaEPhdNAJ7+Dosc9DOIqNy7Q==", 40 | "funding": { 41 | "type": "opencollective", 42 | "url": "https://opencollective.com/bootstrap" 43 | }, 44 | "peerDependencies": { 45 | "@popperjs/core": "^2.10.2" 46 | } 47 | }, 48 | "node_modules/bootstrap-icons": { 49 | "version": "1.7.2", 50 | "resolved": "https://registry.npmjs.org/bootstrap-icons/-/bootstrap-icons-1.7.2.tgz", 51 | "integrity": "sha512-NiR2PqC73AQOPdVSu6GJfnk+hN2z6powcistXk1JgPnKuoV2FSdSl26w931Oz9HYbKCcKUSB6ncZTYJAYJl3QQ==", 52 | "engines": { 53 | "node": ">=10" 54 | } 55 | }, 56 | "node_modules/component-emitter": { 57 | "version": "1.3.0", 58 | "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz", 59 | "integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==" 60 | }, 61 | "node_modules/component-query": { 62 | "version": "0.0.3", 63 | "resolved": "https://registry.npmjs.org/component-query/-/component-query-0.0.3.tgz", 64 | "integrity": "sha1-B/Sdq3Bx+pYGcl31PmB/RorNqs8=" 65 | }, 66 | "node_modules/css-ease": { 67 | "version": "0.0.1", 68 | "resolved": "https://registry.npmjs.org/css-ease/-/css-ease-0.0.1.tgz", 69 | "integrity": "sha1-U3Z5tnyfx8UpaIJbb90h90ksqGw=" 70 | }, 71 | "node_modules/css-emitter-component": { 72 | "version": "0.1.1", 73 | "resolved": "https://registry.npmjs.org/css-emitter-component/-/css-emitter-component-0.1.1.tgz", 74 | "integrity": "sha1-+15MTas81iyTCsrIN7bjTYerKo4=", 75 | "dependencies": { 76 | "event-component": "~0.1.0" 77 | } 78 | }, 79 | "node_modules/event-component": { 80 | "version": "0.1.0", 81 | "resolved": "https://registry.npmjs.org/event-component/-/event-component-0.1.0.tgz", 82 | "integrity": "sha1-gEVVedE0qyfju4C7KGm/lqdunmg=" 83 | }, 84 | "node_modules/has-transitions": { 85 | "version": "0.3.0", 86 | "resolved": "https://registry.npmjs.org/has-transitions/-/has-transitions-0.3.0.tgz", 87 | "integrity": "sha1-BmQ3xYlhOo17oKqjy9QI7MtAjxA=" 88 | }, 89 | "node_modules/has-translate3d": { 90 | "version": "0.0.3", 91 | "resolved": "https://registry.npmjs.org/has-translate3d/-/has-translate3d-0.0.3.tgz", 92 | "integrity": "sha1-7gFXrVtMqKGjNRSp5+9FQVoTIQM=", 93 | "dependencies": { 94 | "transform-property": "0.0.1" 95 | } 96 | }, 97 | "node_modules/move-js": { 98 | "version": "0.5.0", 99 | "resolved": "https://registry.npmjs.org/move-js/-/move-js-0.5.0.tgz", 100 | "integrity": "sha1-GfQt7mH+auklJDbCd5bBImFMPSw=", 101 | "dependencies": { 102 | "after-transition": "0.0.4", 103 | "component-emitter": "^1.2.0", 104 | "component-query": "0.0.3", 105 | "css-ease": "0.0.1", 106 | "has-translate3d": "0.0.3" 107 | } 108 | }, 109 | "node_modules/transform-property": { 110 | "version": "0.0.1", 111 | "resolved": "https://registry.npmjs.org/transform-property/-/transform-property-0.0.1.tgz", 112 | "integrity": "sha1-SGNmL51eW7jwwAZI7/CL6xT9ZfI=" 113 | } 114 | }, 115 | "dependencies": { 116 | "@popperjs/core": { 117 | "version": "2.11.2", 118 | "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.2.tgz", 119 | "integrity": "sha512-92FRmppjjqz29VMJ2dn+xdyXZBrMlE42AV6Kq6BwjWV7CNUW1hs2FtxSNLQE+gJhaZ6AAmYuO9y8dshhcBl7vA==", 120 | "peer": true 121 | }, 122 | "after-transition": { 123 | "version": "0.0.4", 124 | "resolved": "https://registry.npmjs.org/after-transition/-/after-transition-0.0.4.tgz", 125 | "integrity": "sha1-FlNWBQeJPYIOUDI927qu/SrhdVU=", 126 | "requires": { 127 | "css-emitter-component": "~0.1.1", 128 | "has-transitions": "~0.3.0" 129 | } 130 | }, 131 | "bootstrap": { 132 | "version": "5.1.3", 133 | "resolved": "https://registry.npmjs.org/bootstrap/-/bootstrap-5.1.3.tgz", 134 | "integrity": "sha512-fcQztozJ8jToQWXxVuEyXWW+dSo8AiXWKwiSSrKWsRB/Qt+Ewwza+JWoLKiTuQLaEPhdNAJ7+Dosc9DOIqNy7Q==", 135 | "requires": {} 136 | }, 137 | "bootstrap-icons": { 138 | "version": "1.7.2", 139 | "resolved": "https://registry.npmjs.org/bootstrap-icons/-/bootstrap-icons-1.7.2.tgz", 140 | "integrity": "sha512-NiR2PqC73AQOPdVSu6GJfnk+hN2z6powcistXk1JgPnKuoV2FSdSl26w931Oz9HYbKCcKUSB6ncZTYJAYJl3QQ==" 141 | }, 142 | "component-emitter": { 143 | "version": "1.3.0", 144 | "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz", 145 | "integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==" 146 | }, 147 | "component-query": { 148 | "version": "0.0.3", 149 | "resolved": "https://registry.npmjs.org/component-query/-/component-query-0.0.3.tgz", 150 | "integrity": "sha1-B/Sdq3Bx+pYGcl31PmB/RorNqs8=" 151 | }, 152 | "css-ease": { 153 | "version": "0.0.1", 154 | "resolved": "https://registry.npmjs.org/css-ease/-/css-ease-0.0.1.tgz", 155 | "integrity": "sha1-U3Z5tnyfx8UpaIJbb90h90ksqGw=" 156 | }, 157 | "css-emitter-component": { 158 | "version": "0.1.1", 159 | "resolved": "https://registry.npmjs.org/css-emitter-component/-/css-emitter-component-0.1.1.tgz", 160 | "integrity": "sha1-+15MTas81iyTCsrIN7bjTYerKo4=", 161 | "requires": { 162 | "event-component": "~0.1.0" 163 | } 164 | }, 165 | "event-component": { 166 | "version": "0.1.0", 167 | "resolved": "https://registry.npmjs.org/event-component/-/event-component-0.1.0.tgz", 168 | "integrity": "sha1-gEVVedE0qyfju4C7KGm/lqdunmg=" 169 | }, 170 | "has-transitions": { 171 | "version": "0.3.0", 172 | "resolved": "https://registry.npmjs.org/has-transitions/-/has-transitions-0.3.0.tgz", 173 | "integrity": "sha1-BmQ3xYlhOo17oKqjy9QI7MtAjxA=" 174 | }, 175 | "has-translate3d": { 176 | "version": "0.0.3", 177 | "resolved": "https://registry.npmjs.org/has-translate3d/-/has-translate3d-0.0.3.tgz", 178 | "integrity": "sha1-7gFXrVtMqKGjNRSp5+9FQVoTIQM=", 179 | "requires": { 180 | "transform-property": "0.0.1" 181 | } 182 | }, 183 | "move-js": { 184 | "version": "0.5.0", 185 | "resolved": "https://registry.npmjs.org/move-js/-/move-js-0.5.0.tgz", 186 | "integrity": "sha1-GfQt7mH+auklJDbCd5bBImFMPSw=", 187 | "requires": { 188 | "after-transition": "0.0.4", 189 | "component-emitter": "^1.2.0", 190 | "component-query": "0.0.3", 191 | "css-ease": "0.0.1", 192 | "has-translate3d": "0.0.3" 193 | } 194 | }, 195 | "transform-property": { 196 | "version": "0.0.1", 197 | "resolved": "https://registry.npmjs.org/transform-property/-/transform-property-0.0.1.tgz", 198 | "integrity": "sha1-SGNmL51eW7jwwAZI7/CL6xT9ZfI=" 199 | } 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "scrolling-tabs-bootstrap-5", 3 | "version": "1.1.1", 4 | "description": "A simple plugin to create scrollable tabs with Bootstrap 5.", 5 | "main": "./dist/scrollable-tabs.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/SupernovaIC/scrollable-tabs-bootstrap-5.git" 9 | }, 10 | "keywords": [ 11 | "scrollable", 12 | "scrolling", 13 | "tabs", 14 | "bootstrap", 15 | "boostrap", 16 | "bootstrap-5", 17 | "javascript", 18 | "css", 19 | "web", 20 | "front-end", 21 | "move-js", 22 | "css" 23 | ], 24 | "author": "Federico Navarrete ", 25 | "license": "Apache 2.0", 26 | "bugs": { 27 | "url": "https://github.com/SupernovaIC/scrollable-tabs-bootstrap-5/issues" 28 | }, 29 | "homepage": "https://github.com/SupernovaIC/scrollable-tabs-bootstrap-5#readme", 30 | "dependencies": { 31 | "bootstrap": "^5.1.3", 32 | "bootstrap-icons": "^1.7.2", 33 | "move-js": "^0.5.0" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /preview.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SupernovaIC/scrollable-tabs-bootstrap-5/f2b86756fedecb631bbf6d76fb6b907240f00feb/preview.gif -------------------------------------------------------------------------------- /src/css/scrollable-tabs.css: -------------------------------------------------------------------------------- 1 | 2 | .wrapper-nav { 3 | position:relative; 4 | margin:0 auto; 5 | overflow:hidden; 6 | padding:5px; 7 | height:50px; 8 | } 9 | 10 | .list { 11 | position:absolute; 12 | left:0px; 13 | top:0px; 14 | min-width:3500px; 15 | margin-top:0px; 16 | } 17 | 18 | .list li{ 19 | display:table-cell; 20 | position:relative; 21 | text-align:center; 22 | cursor:grab; 23 | cursor:-webkit-grab; 24 | color:#efefef; 25 | vertical-align:middle; 26 | } 27 | 28 | .scroller { 29 | text-align:center; 30 | cursor:pointer; 31 | display:none; 32 | padding:7px; 33 | white-space:no-wrap; 34 | vertical-align:middle; 35 | background-color:#fff; 36 | } 37 | 38 | .pointer {cursor: pointer;} 39 | -------------------------------------------------------------------------------- /src/css/scrollable-tabs.min.css: -------------------------------------------------------------------------------- 1 | .wrapper-nav{position:relative;margin:0 auto;overflow:hidden;padding:5px;height:50px}.list{position:absolute;left:0;top:0;min-width:3500px;margin-top:0}.list li{display:table-cell;position:relative;text-align:center;cursor:grab;cursor:-webkit-grab;color:#efefef;vertical-align:middle}.scroller{text-align:center;cursor:pointer;display:none;padding:7px;white-space:no-wrap;vertical-align:middle;background-color:#fff}.pointer{cursor:pointer} -------------------------------------------------------------------------------- /src/js/scrollable-tabs.js: -------------------------------------------------------------------------------- 1 | //let move = require('move'); 2 | // Function to initialize scrollable tabs for a specific wrapper 3 | function initializeScrollableTabs(wrapper) { 4 | const scrollBarWidths = 40; 5 | const scrollerRight = wrapper.querySelector(".scroller-right"); 6 | const scrollerLeft = wrapper.querySelector(".scroller-left"); 7 | const list = wrapper.querySelector(".list"); 8 | const lastNavLink = list.querySelectorAll(".nav-item.nav-link")[list.querySelectorAll(".nav-item.nav-link").length - 1]; 9 | let btnTriggered = false; 10 | 11 | let widthOfList = function () { 12 | let itemsWidth = 0; 13 | const listLinks = list.querySelectorAll("a"); 14 | 15 | listLinks.forEach((el) => { 16 | let itemWidth = getOuterWidth(el); 17 | itemsWidth += itemWidth; 18 | }); 19 | 20 | return itemsWidth; 21 | }; 22 | 23 | let widthOfHidden = function (w) { 24 | w = (!w) ? 0 : w; 25 | const oW = getOuterWidth(wrapper.querySelector(".wrapper-nav")) - w; 26 | const ww = parseFloat((0 - oW).toFixed(3)); 27 | const hw = (oW - widthOfList() - getLeftPosi()) - scrollBarWidths; 28 | const rp = document.body.clientWidth - (getOuterLeft(lastNavLink) + getOuterWidth(lastNavLink)) - w; 29 | 30 | if (ww > hw) { 31 | return (rp > ww ? rp : ww); 32 | } else { 33 | return (rp > hw ? rp : hw); 34 | } 35 | }; 36 | 37 | let getLeftPosi = () => { 38 | const lp = getOuterLeft(list); 39 | const wrapperLeft = getOuterLeft(wrapper.querySelector(".wrapper-nav")); 40 | 41 | return lp - wrapperLeft; 42 | }; 43 | 44 | let reAdjust = () => { 45 | let rp = document.body.clientWidth - (getOuterLeft(lastNavLink) + getOuterWidth(lastNavLink)); 46 | 47 | if (getOuterWidth(wrapper.querySelector(".wrapper-nav")) < widthOfList() && (rp < 0)) { 48 | scrollerRight.style.display = 'flex'; 49 | unfade(scrollerRight); 50 | } else { 51 | scrollerRight.style.display = 'none'; 52 | } 53 | 54 | if (getLeftPosi() < 0) { 55 | scrollerLeft.style.display = 'flex'; 56 | unfade(scrollerLeft); 57 | } else { 58 | scrollerLeft.style.display = 'none'; 59 | } 60 | 61 | btnTriggered = false; 62 | }; 63 | 64 | scrollerRight.addEventListener("click", () => { 65 | if (btnTriggered) return; 66 | 67 | btnTriggered = true; 68 | 69 | fade(scrollerLeft); 70 | unfade(scrollerRight); 71 | 72 | let wR = getOuterWidth(scrollerRight); 73 | 74 | move(list).add("left", +widthOfHidden(wR), 200).end().then(() => { 75 | reAdjust(); 76 | }); 77 | }); 78 | 79 | scrollerLeft.addEventListener("click", () => { 80 | if (btnTriggered) return; 81 | 82 | btnTriggered = true; 83 | 84 | fade(scrollerRight); 85 | unfade(scrollerLeft); 86 | 87 | let wL = getOuterWidth(scrollerLeft); 88 | 89 | move(list).add("left", -getLeftPosi() + wL, 200).end().then(() => { 90 | reAdjust(); 91 | }); 92 | }); 93 | 94 | window.addEventListener('resize', () => { 95 | reAdjust(); 96 | }, true); 97 | 98 | reAdjust(); 99 | } 100 | 101 | let getOuterLeft = (elem) => elem.getBoundingClientRect().left; 102 | 103 | let getOuterWidth = (elem) => parseFloat(window.getComputedStyle(elem).width); 104 | 105 | function fade(elem) { 106 | elem.style.display = "none"; 107 | elem.style.transition = "opacity 0.6s"; 108 | elem.style.opacity = 0; 109 | } 110 | 111 | function unfade(elem) { 112 | elem.style.display = "block"; 113 | elem.style.transition = "opacity 0.6s"; 114 | elem.style.opacity = 1; 115 | } 116 | 117 | // Initialize scrollable tabs for each tab set 118 | document.querySelectorAll('.tab-wrapper').forEach(wrapper => { 119 | initializeScrollableTabs(wrapper); 120 | }); -------------------------------------------------------------------------------- /src/js/scrollable-tabs.min.js: -------------------------------------------------------------------------------- 1 | function initializeScrollableTabs(e){const t=e.querySelector(".scroller-right"),l=e.querySelector(".scroller-left"),r=e.querySelector(".list"),n=r.querySelectorAll(".nav-item.nav-link")[r.querySelectorAll(".nav-item.nav-link").length-1];let i=!1,a=function(){let e=0;return r.querySelectorAll("a").forEach((t=>{let l=getOuterWidth(t);e+=l})),e},d=()=>getOuterLeft(r)-getOuterLeft(e.querySelector(".wrapper-nav")),o=()=>{let r=document.body.clientWidth-(getOuterLeft(n)+getOuterWidth(n));getOuterWidth(e.querySelector(".wrapper-nav")){if(i)return;i=!0,fade(l),unfade(t);let u=getOuterWidth(t);move(r).add("left",+function(t){t=t||0;const l=getOuterWidth(e.querySelector(".wrapper-nav"))-t,r=parseFloat((0-l).toFixed(3)),i=l-a()-d()-40,o=document.body.clientWidth-(getOuterLeft(n)+getOuterWidth(n))-t;return r>i?o>r?o:r:o>i?o:i}(u),200).end().then((()=>{o()}))})),l.addEventListener("click",(()=>{if(i)return;i=!0,fade(t),unfade(l);let e=getOuterWidth(l);move(r).add("left",-d()+e,200).end().then((()=>{o()}))})),window.addEventListener("resize",(()=>{o()}),!0),o()}let getOuterLeft=e=>e.getBoundingClientRect().left,getOuterWidth=e=>parseFloat(window.getComputedStyle(e).width);function fade(e){e.style.display="none",e.style.transition="opacity 0.6s",e.style.opacity=0}function unfade(e){e.style.display="block",e.style.transition="opacity 0.6s",e.style.opacity=1}document.querySelectorAll(".tab-wrapper").forEach((e=>{initializeScrollableTabs(e)})); --------------------------------------------------------------------------------