A Breakpoint is a lightweight jQuery library for detecting and managing breakpoint changes. Breakpoint was originally written to optimize for large one-page sites with too many links to resize causing performance issues. While it still achieves the previous goal, it has also been rewritten to help manage general breakpoints.
jquery media query, set breakpoint in jquery, jquery responsive, jquery with, clientwidth jquery, jquery window width, javascript get bs breakpoint
How to make use of it:
1. Install jQuery Breakpoints with NPM:
# NPM $ npm install jquery-breakpoints --save
2. Alternatively, you can also download and insert a JavaScript file.
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT" crossorigin="anonymous"></script> <script src="jquery.breakpoints.min.js"></script>
3. Configure the plugin and we are ready to go.
$(function(){ $(window).breakpoints(); });
4. Run a function when the breakpoint changes.
$(window).bind("breakpoint-change", function(event) { console.log(event.from, event.to); }); $(window).bind("breakpoint-change", function(event) { if (event.from === "md") { // ... } if (event.to === "md") { // ... } });
5. Preset breakpoints.
$(window).breakpoints({ breakpoints: [ {"name": "xs", "width": 0}, {"name": "sm", "width": 768}, {"name" : "md", "width": 992}, {"name" : "lg", "width": 1200} ], });
6. Compare breakpoints and perform certain functions.
$(window).on('lessThan-md', function() { // Do something when viewport is less than 992px });
7. API methods.
// Returns the current breakpoint name. $(window).breakpoints("getBreakpoint"); // Returns the current breakpoint width $(window).breakpoints("getBreakpointWidth"); // Destroys the plugin $(window).breakpoints("destroy");
8. More plugin options.
$(window).breakpoints({ // A buffer is set before breakpoints trigger breakpoint-change. // The buffer keeps resizing more performant by not triggering actions prematurely. buffer: 300, // On initializing Breakpoints after the buffer trigger a breakpoint-change so all bindings necessary could happen. // This will return the same event object as regular breakpoint change with event.initalInit. triggerOnInit: false, // Use $(window).outerWidth() over the default $(window).width() for window width calculations. outerWidth: false });
Execute Functions Within Certain Breakpoints Plugin/Github, how to set window width in jquery
See Demo And Download
Official Website(jerrylow): Click Here
This superior jQuery/javascript plugin is developed by jerrylow. For extra Advanced Usages, please go to the official website.