项目作者: akwebapps

项目描述 :
Grab and assign bootstrap size classes to body tag for stylesheet shortcuts.
高级语言: JavaScript
项目地址: git://github.com/akwebapps/ak-ScreenSizeClass.git
创建时间: 2020-01-23T18:50:59Z
项目社区:https://github.com/akwebapps/ak-ScreenSizeClass

开源协议:

下载


akScreenSizeClass

Grab and assign bootstrap size classes to body tag for stylesheet shortcuts. Sometimes it sucks having to deal with @media classes in your stylesheet. Wouldn’t it be easier to reference the size by a class instead?

Initialization & Usage

  1. $.akScreenSizeClass(actionStr,params);
  • actionStr (string; optional)
  • params (obj; optional)

Default Breakpoints & Body Classes

Min Width Max Width Body Class
< 575 .body-xs
576 767 .body-sm
768 991 .body-md
992 1199 .body-lg
1200 > .body-xl

Get Values

  1. var currentClass = $.akScreenSizeClass("class"); //gets the current body class assignment
  2. var currentWidth = $.akScreenSizeClass("width"); //gets the current window width

Reinitialize & Set Body Class

The width is set every time the window is resized but you MAY want to force it to reassign the body class.

  1. $.akScreenSizeClass("set");

Listen for Changes

You can listen for changes. This even will be triggered every time the class is changed.

  1. $(document).on("sizeClassChanged",function(e,data){
  2. //do something with the data
  3. //returns {"width":currentScreenWidth,"class":currentBodyClass}
  4. })

Change Breakpoints

Don’t like the default breakpoints? You can change them by passing the minimum width of each in the params. If the first parameter actionStr is "set" then the breakpoints will be set for the remainer of the page session.

  1. $.akScreenSizeClass("set",{
  2. sm: 576,
  3. md: 768,
  4. lg: 992,
  5. xl: 1200
  6. });