├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── favicon.ico ├── index.html ├── package-lock.json ├── package.json └── src └── bootstrap-detect-breakpoint.js /.gitattributes: -------------------------------------------------------------------------------- 1 | src/bootstrap-detect-breakpoint.js linguist-vendored=false 2 | index.html linguist-documentation -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /.idea -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Stefan Haack (shaack.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bootstrap-detect-breakpoint 2 | 3 | Detect the current Bootstrap breakpoint in JavaScript. 4 | 5 | ## References 6 | 7 | - [Demo page](https://shaack.com/projekte/bootstrap-detect-breakpoint/) 8 | - [GitHub repository](https://github.com/shaack/bootstrap-detect-breakpoint) 9 | - [npm package](https://www.npmjs.com/package/bootstrap-detect-breakpoint) 10 | 11 | ## Usage 12 | 13 | Include the `bootstrap-detect-breakpoint.js`. 14 | 15 | ```html 16 | 17 | ``` 18 | 19 | Get the current breakpoint with 20 | 21 | ```js 22 | var currentBreakpoint = bootstrapDetectBreakpoint() 23 | ``` 24 | which will return an object with the current breakpoint name and index, 25 | like this 26 | 27 | ```json 28 | { 29 | "name": "lg", 30 | "index": 3 31 | } 32 | ``` 33 | 34 | The index goes from 0 to 5, where 0 is "xs" and 5 is for "xxl". 35 | 36 | ## Works in Bootstrap 4 and 5 37 | 38 | In Bootstrap 5 prior 5.3 there is an [issue that the css variables for breakpoints are missing](https://github.com/twbs/bootstrap/issues/36094), which was fixed (by me) with version 5.3. 39 | 40 | Up to version 5.3, you can use the bootstrap-detect-breakpoint script with Bootstrap 5 by simply adding the following to your scss 41 | ```scss 42 | :root { 43 | @each $name, $value in $grid-breakpoints { 44 | --bs-breakpoint-#{$name}: #{$value}; 45 | } 46 | } 47 | ``` 48 | 49 | --- 50 | 51 | Find more high quality modules from [shaack.com](https://shaack.com) 52 | on [our projects page](https://shaack.com/works). 53 | 54 | -------------------------------------------------------------------------------- /favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaack/bootstrap-detect-breakpoint/03f5f05bf8746d35d29dbeacd74ad345a4d882e0/favicon.ico -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |
24 | const output = document.getElementById("breakpoint-output")
25 |
26 | function updateView() {
27 | const currentBreakpoint = bootstrapDetectBreakpoint()
28 | output.innerHTML = "" + JSON.stringify(currentBreakpoint) + "
"
29 | }
30 |
31 | updateView()
32 | window.onresize = updateView
33 |
34 |