Home  >  Article  >  Web Front-end  >  JavaScript code that determines the current fitness in the corresponding layout

JavaScript code that determines the current fitness in the corresponding layout

php中世界最好的语言
php中世界最好的语言Original
2018-03-16 16:37:251293browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn