Bootstrap 4 Breakpoints Detection In JavaScript

Bootstrap 4 Breakpoints Detection In JavaScript
File Size: 4.49 KB
Views Total: 470
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

A super tiny script that detects Bootstrap 4 breakpoints and returns an object containing the current breakpoint name ("xl", "lg", "md", "sm", "xs) and index (0-4).

See Also:

How to use it:

1. Download and load the bootstrap-detect-breakpoint.js script in your Bootstrap project.

<!-- Bootstrap 4 Stylesheet -->
<link rel="stylesheet" href="/path/to/cdn/bootstrap.min.css" />
<!-- Bootstrap 4 JavaScript -->
<script src="/path/to/cdn/jquery.slim.min.js"></script>
<!-- bootstrap-detect-breakpoint.js -->
<script src="src/bootstrap-detect-breakpoint.js"></script>

2. Or load the JavaScript from a CDN.

<!-- jsdelivr CDN -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap-detect-breakpoint/src/bootstrap-detect-breakpoint.js"></script>
<!-- unpkg CDN -->
<script src="https://unpkg.com/bootstrap-detect-breakpoint/src/bootstrap-detect-breakpoint.js"></script>

3. Output the current breakpoint name & index.

// Vanilla JS
document.addEventListener('DOMContentLoaded', function () {
  console.log(bootstrapDetectBreakpoint())
});

// With jQuery
$(document).ready(function () {
  console.log(bootstrapDetectBreakpoint())
});
// output
{
  name: "xl", 
  index: 4
}

Changelog:

v1.0.4 (2020-05-08)

  • Refactor

This awesome jQuery plugin is developed by shaack. For more Advanced Usages, please check the demo page or visit the official website.