bootstrap-detect-breakpoint
Advanced tools
Comparing version 1.0.8 to 1.1.0
{ | ||
"name": "bootstrap-detect-breakpoint", | ||
"version": "1.0.8", | ||
"description": "Detect the current Bootstrap 4 breakpoint in JavaScript", | ||
"version": "1.1.0", | ||
"description": "Detect the current Bootstrap breakpoint in JavaScript", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
# bootstrap-detect-breakpoint | ||
Detect the current Bootstrap 4 breakpoint in JavaScript. | ||
Detect the current Bootstrap breakpoint in JavaScript. | ||
@@ -32,1 +32,14 @@ - [Demo Page](https://shaack.com/projekte/bootstrap-detect-breakpoint/) | ||
The index goes from 0 to 4, where 0 is "xs" and 4 is for "xl". | ||
## Get it working with Bootstrap 5 | ||
In Bootstrap 5 there is an [issue that the css variables for breakpoints are missing](https://github.com/twbs/bootstrap/issues/36094). I already created a [pull request](https://github.com/twbs/bootstrap/pull/36095), but I don't know when it will be merged. | ||
You can make this script work with just adding this to your scss | ||
```scss | ||
@each $name, $value in $grid-breakpoints { | ||
--#{$prefix}breakpoint-#{$name}: #{$value}; | ||
} | ||
``` | ||
const bootstrapDetectBreakpoint = function () { | ||
// cache some values on first call | ||
if (!this.breakpointValues) { | ||
this.breakpointNames = ["xl", "lg", "md", "sm", "xs"] | ||
this.breakpointNames = ["xxl", "xl", "lg", "md", "sm", "xs"] | ||
this.breakpointValues = [] | ||
const isPriorBS5 = !!window.getComputedStyle(document.documentElement).getPropertyValue('--breakpoint-sm') | ||
const selector = isPriorBS5 ? "--breakpoint-" : "--bs-breakpoint-" | ||
for (const breakpointName of this.breakpointNames) { | ||
this.breakpointValues[breakpointName] = window.getComputedStyle(document.documentElement).getPropertyValue('--breakpoint-' + breakpointName) | ||
const value = window.getComputedStyle(document.documentElement).getPropertyValue(selector + breakpointName) | ||
if(value) { | ||
this.breakpointValues[breakpointName] = value | ||
} | ||
} | ||
@@ -18,2 +23,2 @@ } | ||
return null | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19837
6
23
45
1