This time I will bring you the JavaScript code for judging the current adaptability in the corresponding layout. What are the precautions for judging the current adaptability in the corresponding layout? The following are This is a practical case, let’s take a look at it.
Currently, many designs have adopted Responsive layout to adapt to the display of websites or applications on different devices. You often need to determine which screen adaptation level you are currently in in your code.
function isBreakPoint(bp) { // The breakpoints that you set in your css var bps = [320, 480, 768, 1024]; var w = $(window).width(); var min, max; for (var i = 0, l = bps.length; i < l; i++) { if (bps[i] === bp) { min = bps[i-1] || 0; max = bps[i]; break; } } return w > min && w <= max; }
How to use:
if ( isBreakPoint(320) ) { // breakpoint at 320 or less}if ( isBreakPoint(480) ) { // breakpoint between 320 and 480} …
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to the php Chinese website Other related articles!
Recommended reading:
JavaScript code to limit the number of text words
JavaScript code to hide elements one by one
Get the maximum width or height of a group of elements JavaScript code
The above is the detailed content of JavaScript code that determines the current fitness in the corresponding layout. For more information, please follow other related articles on the PHP Chinese website!